LearnFrenzy
Sign in Take a free test

Constructors and the this Keyword · Exercise 1 of 4

Constructors and the this Keyword Constructors MCQ

  • 20 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on Java constructors and the this keyword: default constructors, overloading, this() chaining, initialisation order, private constructors, copy constructors and builders. Pick an option to check your answer instantly.

Question 11 Medium

When does an instance initialiser block { … } run?

A Once, when the class loads
B For every new object, after the superclass constructor and before the rest of this constructor's body
C After the constructor finishes
D Only when called explicitly
Question page & discussion
Question 12 Medium

How many times does a static initialiser block run if 100 objects are created?

A 100
B Once, when the class is initialised
C 0
D 101
Question page & discussion
Question 13 Medium

Are constructors inherited by subclasses?

A Yes, all of them
B No – a subclass declares its own and calls a parent constructor with super(...)
C Only public ones
D Only the no-arg one
Question page & discussion
Question 14 Medium

A class has private final int id; with no initialiser. What must every constructor do?

A Nothing
B Assign id exactly once (directly or through this(...))
C Call setId
D Declare id again
Question page & discussion
Question 15 Easy

What is a copy constructor in Java?

A A constructor generated by the compiler
B A constructor that takes an object of the same class and initialises the new object from it
C The clone() method
D A constructor with no parameters
Question page & discussion
Question 16 Medium

Which is an advantage of a static factory method over a constructor?

A It always creates a new object
B It can have a descriptive name and can return cached objects or a subtype
C It runs faster
D It can be overridden
Question page & discussion
Question 17 Medium

When is the builder pattern the best choice?

A For classes with one field
B For objects with many parameters, especially optional ones, built in a readable way
C For static utility classes
D For interfaces
Question page & discussion
Question 18 Hard

Why is calling an overridable method from a constructor risky?

A It is a compile error
B A subclass override may run before the subclass's fields are initialised, so it sees default values
C It causes infinite recursion
D The method cannot access fields
Question page & discussion
Question 19 Medium

If a constructor throws an exception, what does new return?

A A half-built object
B Nothing – the exception propagates and the variable is not assigned
C null
D A default object
Question page & discussion
Question 20 Hard

What happens if A() calls this(1) and A(int x) calls this()?

A StackOverflowError at run time
B Compile error: recursive constructor invocation
C Each runs once
D The compiler picks one
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links