Why does the super keyword not showing error though not given in first line
super(args...)
is required for the constructor's at first line.
super.property
can be used anywhere in the code
Then you might be making a method call and not Sayin super()
inside constructor.. for instance..
class Superclass
{
public void f1(){
}
}
class Subclass extends Superclass
{
Subclass()
{
System.out.println();
super.f1();
}
}
The above code works fine...
It does for me:
class Superclass
{
}
class Subclass extends Superclass
{
Subclass()
{
System.out.println();
super();
}
}
Compiling gives an error of:
Test.java:10: call to super must be first statement in constructor
super();
^
1 error
Please show a similar short but complete program with it not giving an error. Note that I'm assuming you really have got super();
rather than, say, super.foo();
which is just a call to the superclass implementation of foo();
and can appear anywhere in a method or constructor.