Which program will give correct output :
-
class cons{ cons() { } public void cons(); public static void main (String[] aa){ cons b=new cons(); } }
-
public class cons { cons() { } public cons(int x,int y) { System.out.print(x +" "+ y); } public static void main (String[] aa){ cons b=new cons(); cons obj=new cons(4,2); } }
-
public class cons { public cons(int x) { System.out.print(x); } public static void main (String[] aa){ cons b=new cons(); } }
-
class cons{ cons() { } public float foo () { double f = 32; return f; } public static void main (String[] aa){ cons b=new cons(); } }
The second option compiles and runs successfully because it defines both a default constructor and a parameterized constructor, matching the instantiations in main. The first option has a method signature without a body, the third lacks a default constructor, and the fourth attempts to return a double as a float without casting.