Java Interview Question

Use this intermediate question and answer to prepare for your next Java interview.

Can you instantiate an object for a class that has a subclass overriding all the constructors of its base class?

Example:

  • Class A has 2 constructors, a default constructor and a parameterized constructor.
  • Class B inherits Class A and overrides both constructors.

Can you create an instance of Class A? If no, why? If yes, what are the conditions?


Yes you can instantiate class A under the following conditions:

  • If the constructors are private then it cannot be instantiated outside class A.
  • If the constructors are protected then A cannot be instantiated outside class A or B.
  • If the constructors are public then A can be instantiated anywhere in the program.
  • If the constructors are default visibility then A can be instantiated anywhere in the owning package.

Looking for developers?

Want to learn more about Gigster? Enter your email and we'll be in touch.