Answer to Question #279766 in Java | JSP | JSF for Alexius

Question #279766


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.



1
Expert's answer
2021-12-15T02:09:25-0500
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
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog