java interview questions and answer,java interview questions and answers,java interview questions and answers for experienced,java interview questions and answers pdf,java interview questions and private constructor in java,private constructor in java,private constructor in java with example,private constructor in java inheritance,private constructor in java singleton,calling private constructor in java,accessing private constructor in java,creating private constructor in java,private constructor javascript,private constructor java factory,private constructor java reflection
1.The main aim to reduce creation of object from out side the class.if you take a constructor as private singelton design pattern possible.
2.singleton pattern helps us to keep only one instance of a class at any time.
3.The class with private constructor does not suitable inheritance.
public class MySingleton
{
private static MySingleton ms;
private MySingleton(){
}
public static MySingleton getObject(){
if(ms==null){
ms=new MySingleton();
return ms;
}
}
public class privatedemo
{
public static void main(String [] args){
MySingleton ms=MySingleton.getMySingleton();
}
}
private constructor in java::
1.The main aim to reduce creation of object from out side the class.if you take a constructor as private singelton design pattern possible.
2.singleton pattern helps us to keep only one instance of a class at any time.
3.The class with private constructor does not suitable inheritance.
public class MySingleton
{
private static MySingleton ms;
private MySingleton(){
}
public static MySingleton getObject(){
if(ms==null){
ms=new MySingleton();
return ms;
}
}
public class privatedemo
{
public static void main(String [] args){
MySingleton ms=MySingleton.getMySingleton();
}
}

No comments:
Post a Comment