Loading

Q1.

What is the purpose of a constructor in Java?

A. To initialize objects

B. To destroy objects

C. To define class behavior

D. To call other methods

Q2.

 Which of the following statements about constructors is true?

A. Constructors can have a return type

B. Constructors must have a void return type

C. Constructors have no return type, not even void

D. Constructors always return an object explicitly

Q3.

What happens if you don’t define a constructor in a class?

A. The program throws a compilation error

B. The class cannot be instantiated

C. Java automatically provides a default constructor

D. You must manually define a constructor

Q4.

 Which of the following is not true about constructors?

A. They can be overloaded

B. They can call another constructor using this()

C. They can be inherited by subclasses

D. They can initialize instance variables

Q5.

 How is a constructor different from a method?

A. Constructors can return values

B. Constructors are invoked automatically when an object is created

C. Methods must have the same name as the class

D. Methods cannot take parameters