What will be the result of attempting to compile the following program?
public class Main{ long l1; public void Main (long pLong) { l1 = pLong ; } // (1) public static void main (String args []){ Main a, b ; a = new Main (); // (2) b = new Main (5); // (3) } }
Select 1 option
Correct Option is : C
A. is wrong. But it becomes a valid method if you give a return type.
B. is wrong. The class has an implicit default constructor since the class doesn't have any constructor defined.
C. is correct. Because ( 1) is a method and not a constructor. So there is no constructor that take a parameter.
The declaration at (1) declares a method, not a constructor because it has a return value.
The method happens to have the same name as the class, but that is ok.
The class has an implicit default constructor since the class contains no constructor declarations. This allows the instantiation at (2) to work.