What will be the output of the code given below?
public class Calculator{
private int add(int num1, int num2){
return num1+num2;
}
}
public class Tester{
public static void main(String args[]) {
Calculator calculator = new Calculator();
System.out.println(calculator.add(1,2));
}
}
3
The code will result in a compilation error as the method add cannot be accessed outside the class.
The code will not result in a compilation error but will not display any output.
The code will result in a compilation error as a non-static method cannot be invoked from a static method.
To get all Self Assessment - Programming using Java Exam questions Join Telegram Group https://rebrand.ly/lex-telegram-236dee