超级关键字没有扩展到超类

有一个简单的程序,在构造函数中,super()被调用而没有扩展到超类,我无法理解在这种情况下会做什么呢?

public class Student { private String name; private int rollNum; Student(String name,int rollNum){ super();// I can not understand why super keyword here. this.name=name; this.rollNum=rollNum; } public static void main(String[] args) { Student s1 = new Student("A",1); Student s2 = new Student("A",1); System.out.println(s1.equals(s2)); } } 

每个没有显式扩展另一个类的类都会隐式扩展java.lang.Object 。 所以super()只是调用Object的no-arg构造函数。

请注意,此显式调用是不必要的,因为编译器会为您添加它。 当您想要使用参数调用超类构造函数时,只需要在构造函数中添加一个super()调用。

不需要添加super()因为它是默认添加的。

它将调用Object类的默认构造函数,因为在JAVA中,每个类都默认扩展Object