Multiple choice technology programming languages

Which program will give correct output :

  1. class cons{ cons() { } public void cons(); public static void main (String[] aa){ cons b=new cons(); } }

  2. 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); } }

  3. public class cons { public cons(int x) { System.out.print(x); } public static void main (String[] aa){ cons b=new cons(); } }

  4. class cons{ cons() { } public float foo () { double f = 32; return f; } public static void main (String[] aa){ cons b=new cons(); } }

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

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.