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 multilevel inheritance?
What is multiple inheritance? Give Example
What is super in oop?
How Do you Code Composition and Aggregation in C++ ?
How to call a non virtual function in the derived class by using base class pointer
What are the benefits of interface?
Can private class be inherited?
Why do we use oops?
What is a linked list?
What is polymorphism and example?
Pls...could any one tell me that whether we can access the public data memeber of a class from another class with in the same program. Awaiting for your response Thanku
When is an object created and what is its lifetime?