Write java class that has one instance variable, a programmer defined constructor which initializes that instance variable of the class and one method that accepts an integer value. Write another java class that instantiates an object of the class that was created and calls the method defined in the class. Use comments to indicate a parameter and an argument.
class Int {
int value;
Int(int value) {
this.value = value;
}
public int add(int other) {
return value + other;
}
}
public class Main {
Int integer = new Int(7);
System.out.println(integer.add(7)); // 7
}
Comments
Leave a comment