Can we create object of class with private constructor?

Answers were Sorted based on User's Feedback



Can we create object of class with private constructor?..

Answer / cracker singh

yes

Is This Answer Correct ?    12 Yes 5 No

Can we create object of class with private constructor?..

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

Can we create object of class with private constructor?..

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

Can we create object of class with private constructor?..

Answer / supriya

No we cannot create the objects of class with private
constructor outside the class

Is This Answer Correct ?    0 Yes 1 No

Can we create object of class with private constructor?..

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

Post New Answer

More OOPS Interview Questions

define a string class. overload the operator == to compare two strings

2 Answers   Birla, Ericsson, HCL, Infosys, Infotech, MCAS, Satyam,


why overriding?

3 Answers  


what is multithreading in c++ , what is difference between multithreading and singlethreading.

4 Answers  


what is polymorphism?

4 Answers  


Why is oop useful?

0 Answers  


Is html an oop?

0 Answers  


What is persistence in oop?

0 Answers  


How would you stop a class from class from being derived or inherited.

18 Answers   Ness Technologies,


What do you mean by stack program? Get me an example stack program?

4 Answers  


How do you answer polymorphism?

0 Answers  


Can main method override?

0 Answers  


write a program in c++ to overload the function add (s1,s2) where s1 and s2 are integers and floating point values.

4 Answers  


Categories