1.

If a constructor is defined in protected access, then?(a) It’s instance can be created inside the subclasses(b) It’s instance can be created anywhere in the program(c) It’s instance can be created inside the subclasses and main() function(d) It’s instance can be created inside the parent class onlyI have been asked this question in an interview for internship.I need to ask this question from Protected Access Specifier topic in section Access Specifiers of Object Oriented Programming

Answer»

Right option is (a) It’s instance can be created INSIDE the subclasses

The explanation: The instances will be allowed to be created only inside the sub classes. This is because the protected MEMBERS will be inherited and hence the CONSTRUCTOR too. This will ALLOW the subclasses to call the constructor WHENEVER an object is created.



Discussion

No Comment Found

Related InterviewSolutions