What happens when constructor is defined in private section.. need the answer very urgentlyy!! tomorrow is my exam.. help me peepz!!
Answers
Answered by
0
The private and public functionality and inheritance of them probably depends on the OOPS language and environment. Different languages may have different implementations.
When a method or data is designated as private, it not accessible from outside that class. But the method can be called implicitly by the other methods in the same class. There is a special purpose why it is done.
We cannot instantiate this object from other classes as constructor cannot be called. It is used in a class with all static members ie., a static class. This is accessible from any where and no instantiation is needed or, is to be done.
This is done in cases of singleton object instance. Only one instance is created and is accessible from any where. Perhaps it contains global data and methods.
Also, a class is prevented from being extended or inherited. so no sub classes.
This is used in case of constants only class for preventing instantiation.
Also when factory supplied multiple constructor methods are available with names (which are more readable names), we have the constructor private. The appropriate constructor is called explicitly.
Also, it is possible that a public constructor is used during instantiation and that method uses the private constructor in the same class to perform certain tasks.
When a method or data is designated as private, it not accessible from outside that class. But the method can be called implicitly by the other methods in the same class. There is a special purpose why it is done.
We cannot instantiate this object from other classes as constructor cannot be called. It is used in a class with all static members ie., a static class. This is accessible from any where and no instantiation is needed or, is to be done.
This is done in cases of singleton object instance. Only one instance is created and is accessible from any where. Perhaps it contains global data and methods.
Also, a class is prevented from being extended or inherited. so no sub classes.
This is used in case of constants only class for preventing instantiation.
Also when factory supplied multiple constructor methods are available with names (which are more readable names), we have the constructor private. The appropriate constructor is called explicitly.
Also, it is possible that a public constructor is used during instantiation and that method uses the private constructor in the same class to perform certain tasks.
kvnmurty:
click on thanks button above pls;;select best answer
Similar questions