老师作业还有一个疑问

老师作业还有一个疑问

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package jicheng.one1;
 
public class Car {
private String color;
private String userName;
public Car() {}
public Car(String color,String userName) {
    this.setColor(color);
    this.setUserName(userName);
}
    public String getColor() {
    return color;
}
 
public void setColor(String color) {
    this.color = color;
}
 
public String getUserName() {
    return userName;
}
 
public void setUserName(String userName) {
    this.userName = userName;
}
public void use() {
    System.out.println("我是机动车!");
}
public boolean equals(Object obj) {
    if(obj==null)
        return false;
    Car sc=(Car)obj;
    if(this.getColor().equals(sc.getColor())&&this.getUserName().equals(sc.getUserName()))
    return true;
    else
        return false;
}
public boolean equals(Car obj) {
    if(obj==null)
        return false;
    if(this.getColor().equals(obj.getColor())&&this.getUserName().equals(obj.getUserName()))
    return true;
    else
        return false;
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
 
    }
 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package jicheng.one1;
 
public class taxi extends Car {
    private String company;
    public taxi() {}
   public taxi(String color,String userName,String company) {
       this.setCompany(company);
       this.setColor(color);
       this.setUserName(userName);
   }
 
    public String getCompany() {
        return company;
    }
 
 
    public void setCompany(String company) {
        this.company = company;
    }
final public void ride() {
    System.out.println(this.getUserName()+"出租车是所属于在"+this.getCompany()+"公司的");
@Override
public void use() {
    // TODO Auto-generated method stub
    System.out.println("出租车是提高市民条件之一");
}
@Override
public String toString() {
    // TODO Auto-generated method stub
    return this.getUserName()+"拥有一辆"+this.getColor()+"的出租车";
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
 
    }
 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package jicheng.one1;
 
final public class HomeCar extends Car{
private int num;
public HomeCar() {}
public HomeCar(String color,String userName,int num) {
    super(color,userName);
    this.setNum(num);
    }
    public int getNum() {
    return num;
}
public void setNum(int num) {
    this.num = num;
}
public void display() {
    System.out.println(this.getUserName()+"拥有的"+this.getColor()+"颜色的私家车有"+this.getNum()+"个座位");
}
public void display(int num) {
    System.out.println("加用私家车大多有"+this.getNum()+"个座位");
}
    public static void main(String[] args) {
        // TODO Auto-generated method stub
 
    }
 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package jicheng.one2;
import jicheng.one1.*;
public class ce5 {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
 Car one=new Car("蓝色","张小泉");
 Car two=new Car("蓝色","张小泉");
   one.use();
   System.out.println("one与two属性比较"+one.equals(two));
   taxi sc1=new taxi("蓝色","张小泉","长生");
   sc1.ride();
   sc1.use();
   System.out.println(sc1);
   System.out.println(sc1.toString());
   HomeCar sc2=new HomeCar("紫色","张二娘",7);
   sc2.display();
    
    }
 
}

https://img1.sycdn.imooc.com//climg/6315c19c093915ab08120209.jpg


https://img1.sycdn.imooc.com//climg/6315c19c099c1e6806560083.jpg


https://img1.sycdn.imooc.com//climg/6315c19c09314d5b15810330.jpg

为什么是重载的两个方法,sc2.display();直接两个方法都输出了不是应该只输出一个吗


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
不惧岁月 提问者 2022-09-05 17:33:56
看错了老师,抱歉哈
  • 同学你好,疑问解决就好,后续有疑问可继续在问答区发起新的提问。

    祝学习愉快~

    2022-09-05 17:36:35
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码