Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how can i access a private contructor.

  Asked By: Arnold    Date: Dec 02    Category: Java    Views: 482

how can i access a private contructor.
please give a sample



4 Answers Found

Answer #1    Answered By: Haboos Kauser     Answered On: Dec 02

Is private, only the class may access  a private  constructor.

Answer #2    Answered By: Bama Cohen     Answered On: Dec 02

you can use a private  constructor from public constructor for example,
but no direct way, as far as i know,,,

Answer #3    Answered By: Hadil Khan     Answered On: Dec 02

u can access  a private  conustructor by making a call from one
of the public constructor of that class and using that constructor to create an
object of that class. u have to place a call to that private constructor from
which ever constructor u want.

Answer #4    Answered By: Dale Jones     Answered On: Dec 02

See this sample  code--

Class A{
private A(){


public static A CreateObject(){
return new A();

Class B{
public static void main(String arg[]){
A a=A.CreateObject();

Hope u would get it. Well why do u need this actully this is used for
singletone pater n the code whc i hav given here is not exactly
singleton of pattern. (I can do tht also).

Didn't find what you were looking for? Find more on how can i access a private contructor. Or get search suggestion and latest updates.