what is difference between a construct having super function and without it.
Well, it can be easily tested. They are actually the same for this case.
More importantly, you probably want to know when and how to use super.
Running the following codes:
public class Test
{
public static void main(String[] args)
{
new Students("a", "b");
}
}
class Parent
{
public Parent(){
System.out.println("Parent class constructor invoked");
}
}
class Students extends Parent
{
String name;
String address;
public Students(String name, String address) {
super();
this.name = name;
this.address = address;
}
}
OUTPUT:
Parent class constructor invoked
Now we remove the super()
;
class Students extends Parent
{
String name;
String address;
public Students(String name, String address) {
this.name = name;
this.address = address;
}
}
OUTPUT:
Parent class constructor invoked
Just like how classes are implicitly extending to Object
even when you don't extend them to something. "By default" a super();
will be called in every constructor if one is not given by you.