package day2;
import java.text.FieldPosition;
public class Test {
public static void main(String[] args) {
FieldPosition fp = new FieldPosition(10);
FieldPosition fp1 = new MyTest(8);
// MyTest fp2 = (MyTest)fp; 子类对象可以直接转化为基类,而基类对象不能直接转化为子类对象
FieldPosition fp3 = (FieldPosition)(new MyTest(8));
System.out.println(fp.equals(fp1));
System.out.println(fp1.equals(fp));
System.out.println(fp1.equals(fp3));
}
}
class MyTest extends FieldPosition{
public MyTest(int x){
super(x);
}
}
测试备用
子类对象可以直接转化为基类,而基类对象不能直接转化为子类对象
最新推荐文章于 2022-09-16 15:50:51 发布