Why we generally declare constructor as public member?
Answers
Answered by
0
Answer:
I always seen constructors are implicitly public. So why private constructor is useful? Or is it not useful at all. Because nobody could ever call it, or never make an object(because of the private constructor) ! And that is my second question.
Answered by
0
If we making the object of class can be initialized anywhere in the program we declared as public constructor
Explanation:
- The public constructor also means it can be accessible outside the class The other class can also getting them in a simply manner however if we make the constructor as private it is not accessible outside the class
- Also we make constructor the constructor as public to initialized the class any where in the program .
- We used the public keyword for declaring the public constructor .
For example
class test1 // creating the class test1
{
public test1() // declaring public constructor
{
// statement
}
}
Learn More :
https://brainly.in/question/5798383
Similar questions