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

What is the full form of oops?

0 Answers  


what is the diffrence between c# and c++

5 Answers  


Give an example where we have to specifically use C programming language and C++ programming language cannot be used?

0 Answers   CAT,


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

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


1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321

2 Answers  






Question: Write a program that prints a paycheck. Ask the program user for the name of the employee, the hourly rate, and the number of hours worked. If the number of hours exceeds 40, the employee is paid “time and a half”, that is, 150 percent of the hourly rate on the hours exceeding 40. Be sure to use stepwi se refine ment and break your solution into several functions. Use the int_name function to print the dollar amount of the check.

0 Answers  


what is the function of 'this' operator ?

7 Answers   Wipro,


Why do we use oop?

0 Answers  


why freind function takes more parameter than normal member function in c++?

1 Answers   IBM,


What are different types of JVM's? for example we use dalvik jvm for android then what about the remaining operating systems?

0 Answers   IBM,


Why many objects can working together? How objects working togetherM I want to see example code.

2 Answers  


How Do you Code Composition and Aggregation in C++ ?

3 Answers   IBM, NET,


Categories