You cannot call super()
like this:
class B extends A {
super(1,2,3);
}
super()
OR this()
should be the first statement in a constructor. First correct this basic mistake of yours before going further. super()
is used by default even if you don't explicitly use it.
class B extends A {
B (){
super(1,2,3);
}
}
This is the right way. Please Read about Constructors and Java language basics first before posting questions.
EDIT
I didn't notice that someone edited you question to add super(1,2,3)
in a constructor, now answering your questions as follows:
Does the statement super(1,2,3) in the class B create a private fields same as the private fields in the class A? Or is it illegal to use this statement because B cant inherit the private fields of A?
No, by calling super(1,2,3)
all you're doing is passing 3 integer values to the base class constructor public A(int a, int b , int c)
After that you're assigning these values to the private instance variables of base class, you're not making a separate fields for class B, if thats what you asked, and No B
class still can't access base class instance variables directly (by stating directly I mean by inheritance or making an instance, there are other ways like setters/getters etc)
And we suppose that we didn't use the super constructor in the class B then normally the computer will call the default constructor of the class A. We know that private fields are not inherited in Java so what will the default constructor initialize in this state ?
No, if you don't use a constructor in B
class which uses super(int, int, int)
to match the arguments of base class constructor (int a, int b , int c)
then your code won't even compile. The default constructor will call the no-args constructor of Base class, but since Base class has no default constructor you'll get compilation error!