1.

What happens if constructor of class A is made private?(a) Any class can instantiate objects of class A(b) Objects of class A can be instantiated only within the class where it is declared(c) Inherited class can instantiate objects of class A(d) classes within the same package as class A can instantiate objects of class AThis question was posed to me in homework.I'd like to ask this question from Access Control topic in section Classes and Methods of Java

Answer»

Right CHOICE is (b) Objects of CLASS A can be INSTANTIATED only WITHIN the class where it is declared

To explain I would say: If we make any class constructor PRIVATE, we cannot create the instance of that class from outside the class.



Discussion

No Comment Found

Related InterviewSolutions