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;
}
}