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?
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:
privatethen it cannot be instantiated outside class A.
protectedthen A cannot be instantiated outside class A or B.
publicthen A can be instantiated anywhere in the program.
defaultvisibility then A can be instantiated anywhere in the owning package.