永发信息网

this调用构造方法

答案:2  悬赏:40  手机版
解决时间 2021-04-01 20:34
  • 提问者网友:末路
  • 2021-03-31 23:08
this调用构造方法
最佳答案
  • 五星知识达人网友:未来江山和你
  • 2021-04-01 00:37
(1) Employee 类中的构造函数中的this代表是构造函数的调用,根据构造函数的参数,调用的是employee(String n,int s)函数。
(2) ThisClass中的this是代表bank这个对象,也就是说someMethod这个方法的参数一个Bank对象,参数中的this就是调用当前方法的对象,另外还可以用this引用属性对当前对象的属性进行复制像下面这样
public class Rectangle {
private int x, y;
private int width, height;

public Rectangle() {
this(0, 0, 1, 1);
}
public Rectangle(int width, int height) {
this(0, 0, width, height);
}
public Rectangle(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
...
}追问那再请问一下这个意思是不是说下面两个构造函数public Employee(String n)和public Employee()实际上调用的还是第一个构造函数public Employee(String n,int s)???谢谢~~~追答是的
全部回答
  • 1楼网友:孤独入客枕
  • 2021-04-01 01:13
可以简单的理解为所有"this"都等同于该class的名称。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯