I've just started learning Java and I am stuck at this MCQ:
Assume class Temp is defined as belowand the statment Temp a= new temp()
is
successfully executed Which of the statement is illegal in Java?
class Temp {
public static int i;
public void method1() { }
public static void method2() { }
}
A. System.out.println(i);
B. Temp.method1();
C. a.method1();
D. Temp.method2();
The answer is B, but I can't understand why. Is it because a void method cannot be defined using the dot notation unless it's static?