About Question com.enthuware.ets.scjp.v6.2.260 :
Posted: Sat Apr 21, 2012 12:22 pm
Regarding this question: the answer being a compilation error on line 2.
public class TestClass
{
public static void main(){ new TestClass().sayHello(); } //1
public static void sayHello(){ System.out.println("Static Hello World"); } //2
public void sayHello() { System.out.println("Hello World "); } //3
}
Why is the error on line 2 rather than on line 3? I see line 2 as correct while line 3 repeats the method signature resulting in the error. Is there a rule about where errors are indicated?
If I compile this code on the command line I get the following response:
sayHello() is already defined in .....TestClass() public void sayHello() {...} //3
Thanks
public class TestClass
{
public static void main(){ new TestClass().sayHello(); } //1
public static void sayHello(){ System.out.println("Static Hello World"); } //2
public void sayHello() { System.out.println("Hello World "); } //3
}
Why is the error on line 2 rather than on line 3? I see line 2 as correct while line 3 repeats the method signature resulting in the error. Is there a rule about where errors are indicated?
If I compile this code on the command line I get the following response:
sayHello() is already defined in .....TestClass() public void sayHello() {...} //3
Thanks