Consider the following class definition:
public class Main{ public static void main (){ new Main ().sayHello (); } //1 public static void sayHello (){ System.out.println ("Static Hello World"); public void sayHello () { System.out.println ("Hello World "); } //3 }
What will be the result of compiling and running the class?
Select 1 option
Correct Option is : D
You cannot have two methods with the same signature, name and parameter types, in one class.
If you put one sayHello()
method in other class, it won't compile because you cannot override/hide a static method with a non static method and vice versa.