To answer this question, let's go through each option and determine whether it is true or false:
A. The default constructor initializes method variables.
This statement is false. The default constructor does not initialize method variables. It is responsible for initializing instance variables to their default values.
B. The default constructor has the same access as its class.
This statement is true. The default constructor has the same access modifier as its class. For example, if a class has public access, the default constructor also has public access.
C. The default constructor invokes the no-arg constructor of the superclass.
This statement is true. If a class extends another class, and the subclass does not explicitly call a superclass constructor, the default constructor of the subclass will automatically invoke the no-arg constructor of the superclass.
D. If a class lacks a no-arg constructor, the compiler always creates a default constructor.
This statement is false. If a class lacks a no-arg constructor, and there are no other constructors defined, the compiler will not create a default constructor. In such cases, the class can only be instantiated using constructors with arguments.
E. The compiler creates a default constructor only when there are no other constructors for the class.
This statement is true. The compiler creates a default constructor for a class only when there are no other constructors explicitly defined in the class. Once a class has any constructor defined, including a parameterized constructor, the compiler will not create a default constructor.
Therefore, the correct statements are:
B. The default constructor has the same access as its class.
C. The default constructor invokes the no-arg constructor of the superclass.
E. The compiler creates a default constructor only when there are no other constructors for the class.