Computer Applications

'Accessibility of a constructor greatly affects the scope and visibility of their class.' Elaborate this statement.

Java Constructors

2 Likes

Answer

Every time an object is created, it is automatically initialised by the constructor of the class. Therefore, it is very much necessary for the constructor of a class to be accessible by the function in which the object is created. If the constructor of a class is declared 'private' or 'protected', then the scope and visibility of the constructor (and the class) is defined by the rules of the access specifier.

In such a case, a function not having access to constructor of a class cannot declare and use objects of that class. Hence, accessibility of a constructor greatly affects the scope and visibility of their class.

Answered By

2 Likes


Related Questions