package Test;

public class L3_1 {
    public static void main(String[] args)
    {
        C c1=new C(100);
        C c2=new C(100);
        System.out.println(c1.equals(c2));
    }
}
class B
{
    private int i;
    
    B(int i)
    {
        this.i=i;
    }
    public boolean equals(B b2)  //面向对象-->多态
    {
        if(this.i==b2.i)
            return true;
        else return false;
    }
}
class C extends B //面向对象-->继承
{
    private int j;
    C(int j)
    {
        super(j);    //初始化父类的带参数构造函数->B(int i)
        this.j=j;
    }
    public boolean equals(B b2)
    {
        C c=(C)b2;  //传递的参数是B类,需要强制转换
        if (this.j==c.j)
            return true;
        else return false;
    }
}

相关文章:

  • 2022-01-05
  • 2021-08-18
  • 2021-05-11
  • 2022-12-23
  • 2021-11-24
  • 2021-12-03
  • 2021-12-29
猜你喜欢
  • 2021-07-28
  • 2022-12-23
  • 2021-05-12
  • 2022-12-23
  • 2021-08-15
  • 2021-04-12
  • 2022-12-23
相关资源
相似解决方案