Originally posted by Karthik Rajashekaran:
class Vict{
private Vict(){//1
System.out.print("Vict");
}
}
public class BLBeck extends Vict{
public static void main(String argv[]){
new BLBeck();
}
BLBeck(){
System.out.print("BLBeck");
}
}
Here in //1 the construtor is marked as private .
But when i compiled it is giving an error
as constructor can be declared as private then why it is giving compilor error.
Also when we should use construtor as private to make it compile perfectly
As somebody said, the superconstructor is not visible when you call "super" because you have marked it private.
NO PRIVATE DATA/METHODS IS INHERITED or avaiiable outside the class even by the super keyword.
The thing is that, when you need your class to have subclasses, there should be atleast one constructor that is non-private and which
you should "explicitly call" from your subclass unless that constructor is the no-argument constructor.
And if you want to instantiate the class,
a> from the same package> one no-modifier constructor or a constructor with greater access.
b> from elsewhere> public
c> subclass from outside the package> one protected or public
hope that helps.