Java MCQs – Constructors

11.) Which of the following statements about constructors is incorrect?

A) Constructors can be inherited by subclasses.
B) Constructors can have access modifiers.
C) Constructors can have parameters.
D) Constructors can be marked as “static.”

Answer: Option D

Explanation: Constructors cannot be marked as “static” because they are used to initialize object instances and are not associated with the class itself.

12.) In Java, what is the purpose of a parameterized constructor?

A) To create multiple constructors with the same parameters.
B) To accept arguments and initialize object attributes.
C) To prevent the instantiation of a class.
D) To allow only private access to the constructor.

Answer: Option B

Explanation: A parameterized constructor allows you to pass arguments when creating an object and use those arguments to initialize the attributes of the object.

13.) Which of the following statements regarding constructors is true?

A) A class can have multiple constructors with the same number and type of parameters.
B) Constructors can be defined as abstract methods.
C) Constructors can return values..
D) Constructors can have a different name than the class.

Answer: Option A

Explanation: Overloaded constructors can have the same number and types of parameters, differing only in the way they initialize the object.

14.) Which of the following is true about the order of constructor invocation during object creation in Java?

A) Subclass constructors are invoked before superclass constructors.
B) Constructors of all classes are invoked simultaneously.
C) Superclass constructors are invoked before subclass constructors.
D) Constructor invocation order is random.

Answer: Option C

Explanation: During object creation, superclass constructors are invoked first, followed by subclass constructors, ensuring that superclass attributes are initialized before subclass attributes.

15.) What happens if a constructor does not explicitly call a constructor using the this() or super() keywords?

A) An error occurs, and the program does not compile.
B) The constructor automatically calls the default constructor.
C) The compiler generates a call to the parameterless constructor.
D) The constructor remains uninitialized.

Answer: Option B

Explanation: If a constructor does not explicitly call a constructor using this() or super(), the compiler automatically inserts a call to the default constructor.

16.) In Java, can a constructor be marked as both “static” and “final”?

A) Yes, to prevent the constructor from being overridden.
B) Yes, to ensure the constructor is accessible without object creation.
C) No, “static” and “final” modifiers cannot be applied together to a constructor.
D) No, constructors cannot have access modifiers.

Answer: Option C

Explanation: Constructors cannot be marked as “static” or “final”; they are automatically called during object creation and cannot be overridden or modified.

17.) In Java, can a constructor call itself recursively using the this() keyword?

A) Yes, it is a common practice for constructor initialization.
B) Yes, but only if the constructor is marked as “private.”
C) No, recursive constructor calls using this() are not allowed.
D) No, constructors cannot use this() keyword.

Answer: Option B

Explanation: A constructor can call itself using the this() keyword, but this practice is typically limited to private constructors to avoid unintended recursion.

18.) Which of the following statements is true regarding the use of this() and super() together in a constructor?

A) Both this() and super() can be used together in any constructor.
B) Only this() can be used to call another constructor within the same class.
C) Only super() can be used to call a constructor of the superclass.
D) Using both this() and super() together causes a compilation error.

Answer: Option C

Explanation: Only the super() keyword can be used to call a constructor of the superclass. Using this() and super() together would result in a compilation error.

19.) Which of the following is not a valid use of constructors in Java?

A) Initializing instance variables
B) Allocating memory for an object
C) Creating multiple instances of a class
D) Implementing interface methods

Answer: Option D

Explanation: Constructors are used for object initialization and memory allocation. Interface methods are implemented in the class using regular methods, not constructors.