Declarations and Access Control

Q1: What will be the output of the program?
public class A
{ 
    void A() /* Line 3 */
    {
        System.out.println('Class A'); 
    } 
    public static void main(String[] args) 
    { 
        new A(); 
    } 
}

A An exception is thrown at line 3.

B The code executes with no output.

C Compilation fails.

D Class A

ANS:A - Class A

Option D is correct. The specification at line 3 is for a method and not a constructor and this method is never called therefore there is no output. The constructor that is called is the default constructor.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.