Can we create object of class with private constructor?
Answers were Sorted based on User's Feedback
Answer / fareed
yes we can
public class Person{
privat Person(){
}
public hai(){
System.out.prinln("hai guys");
}
public static Person getobj(){
return new Person();
}
public class Manage{
public static void main(String[] args){
Person pr=Person.getobj();
pr.hai();
}
}
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rajneesh
Public class mainclass
{
private static mainclass _obj = null;
private constr()
{
}
public static mainclass obj
{
get
{
return _obj
}
}
}
after that you can access the obj in other class .
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / supriya
No we cannot create the objects of class with private
constructor outside the class
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / rahul dhangar
class Rahul
{
private:
int a,b,c;
Rahul()
{ cout<<"enter the no";
cin>>a>>b;
c=a+b;
cout<<c;
}
};
void main()
{
Rahul();
getch();
}
| Is This Answer Correct ? | 0 Yes | 4 No |
What is class in oop with example?
why destructor is not over loaded?
Generally, in all C++ programs, texts are in white colour. Can we change the colour of the text(either input or output or both)? If so, help me out.
Whats oop mean?
Program to print 0 to 9 in cross order
Which is the only operator in C++ which can be overloaded but NOT inherited?
We have a scale and 7 balls. 1 ball is heavier than all the rest. How to determine the heaviest ball with only 3 possible weighing attempts?
What is encapsulation?
what is the function of 'this' operator ?
What is Inheritance, Multiple Inheritance, Shared and Repeatable Inheritance?
What is a superclass in oop?
what is Class in oops with example?