
假如一个类A有两个构造函数A(),和A(int i),当你在对A进行实例化的时候,如果你写A a = new A();那么就会调用没有参数的A(),而如果你写A a = new A(123);那么就会调用有参数的A(int i);
带参数指调用对应带构造函数
比如你带A b=new A(String abc);
A类的定义
public class A{
String str;
int a;
public A(String str){
thisstr=str;
}
public A(String str,int a){
thisstr=str;
thisa=a;
}
}
一个类可能会有几个不同带构造函数,传带参数不同,可能调用的构造函数不同
public class Parent {
private String _param;
public Parent(String param) {
this_param = param;
}
}
class Child extends Parent {
public Child(String param) {
super(param);
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)