Constructors

1.If a class does not explicitly define a constructor, what happens?
  • A. The class cannot be instantiated
  • B. The compiler provides a default constructor
  • C. The JVM generates a random constructor
  • D. The program will not compile

The compiler provides a default constructor

The compiler provides a default constructor

2.If a class does not explicitly define a constructor, what happens?
  • A. The class cannot be instantiated
  • B. The compiler provides a default constructor
  • C. The JVM generates a random constructor
  • D. The program will not compile

The compiler provides a default constructor

The compiler provides a default constructor

3.What happens if you call this () and super () together inside a constructor?
  • A. Both execute sequentially
  • B. Only this () executes
  • C. Compilation error occurs
  • D. The constructor executes normally

Compilation error occurs

Compilation error occurs

4.What will happen if a constructor calls itself recursively?
  • A. The program runs normally
  • B. The recursion continues infinitely and throws StackOverflowError
  • C. The constructor exits automatically
  • D. Java allows self-recursive constructors

The recursion continues infinitely and throws StackOverflowError

The recursion continues infinitely and throws StackOverflowError

5.How can a constructor be prevented from being inherited?
  • A. By making the constructor private
  • B. By declaring the class as final
  • C. By overriding the constructor in the subclass
  • D. By using static keyword

By making the constructor private

By making the constructor private