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 |
State what is encapsulation and friend function?
What is a function in oop?
What is the real time example of inheritance?
explain defference between structure and class with example
write a c++ code of diagonal matrix.
What is coupling in oop?
difference between overloading and overridding
Can you explain polymorphism?
Input: enter the value:1234 output: 1 2 3 4 write a program to get above output.....
4 Answers Bally Technologies, IBM, SoftSol,
What is class encapsulation?
Can you inherit a private class?
What is the difference between declaration and definition?