这两个构造函数之间有什么区别。
public Students(String name, String address) {
super();
this.name = name;
this.address = address;
}
/*Here is constructor without super function call.*/
public Students(String name, String address) {
this.name = name;
this.address = address;
}发布于 2015-08-27 17:09:50
没有区别,这只是一个明示和含蓄的问题。在第二种情况下,如果从父类继承的话,它会隐式调用这个学生类的超级构造函数。读更多关于这个的文章。你可以找到更多的信息,如果你谷歌它。
public class A {
//there is a hidden constructor. Even if you explicitly write it
//public A(){
//}
}
public class B extends A {
private int i;
public B(int x){
this.i = x;
}
}创建对象表单B时,首先隐式调用A的构造函数。但是您可以显式地指定它。
作为
public B(int x){
super();
this.i = x;
}https://stackoverflow.com/questions/32255478
复制相似问题