Computer Applications
'Accessibility of a constructor greatly affects the scope and visibility of their class.' Elaborate this statement.
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.
Related Questions
How can objects be initialized with desired values at the time of object creation ?
When a compiler can automatically generate a constructor if it is not defined then why is it considered that writing constructors for a class is a good practice ?
List some of the special properties of the constructor functions.
What is a parameterized constructor ? How is it useful ?