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 |
define a string class. overload the operator == to compare two strings
2 Answers Birla, Ericsson, HCL, Infosys, Infotech, MCAS, Satyam,
why overriding?
what is multithreading in c++ , what is difference between multithreading and singlethreading.
what is polymorphism?
Why is oop useful?
Is html an oop?
What is persistence in oop?
How would you stop a class from class from being derived or inherited.
What do you mean by stack program? Get me an example stack program?
How do you answer polymorphism?
Can main method override?
write a program in c++ to overload the function add (s1,s2) where s1 and s2 are integers and floating point values.