Hi Bindu,
in my opinion...,to answer this question, first we have to understand why
java allowed constructor to be declare private.
The reason why this constructor is private is some programmers might want to control how an object is created and prevent someone from directly accessing a particular constructor, because "private" is accessible only to the class which defines it.
So user can not create this object via it's constructor.
But usualy the programmers define a static method for the user to create an object of that class.
for example :
here I changed you code to make it work...
-----------------------------------------------
class A{
private A(){}
public static A makeA() {return new A();}
}
public class B {
public static void main(
String[] args) {
A a = A.makeA();
}
}
-----------------------------------------------
it works...!,
BUT this works only with COMPOSITION, not inheritance, as you see, i did not use keyword "extends A" in class B, because if you use extends, this code dosen't work.
because one of inheritance side effect is :
"Java automatically inserts calls to the base-class constructor in the derived-class constructor - either using default constructor or using super keyword".
that's why when you extend to the Base class using "class B extends A", it won't work, because the derived class can not call the base class constructor (again, it's private).
Hope this Help
stevie