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

Can we create object of class with private constructor?

5 Answers  


who is the father of OPPS

4 Answers   Infosys, TCS,


What is destructor give example?

0 Answers  


What is encapsulation with example?

0 Answers  


Write a program in c++ to read two floating point numbers and find their sum and average.

2 Answers  






What is inheritance and how many types of inheritance?

0 Answers  


given a set based questions and 5 questions based on it next data sufficiciency questions 2 and 2/3 english sentence completion with options very easy and 2 synononmys paragraph with 10 questions 10 minutes replace =,-,*,% with -,%,+,* type questions 5 3 questions lik following itssickhere itssickthere itssickhere istsickhere which is nt alike the others very easy

0 Answers   DELL,


How can we use the preprocessor #if and #elseif.

2 Answers  


what is the diffrence between c# and c++

5 Answers  


What is stream in oop?

0 Answers  


WAP find square root of any number (without using sqrt() )?

3 Answers  


What is object and class in oops?

0 Answers  


Categories