Java中对象类型如何进行转换
导语:Java中对象类型如何进行转换呢?下面是小编给大家提供的Java中对象类型的强制转换代码实现,大家可以参考阅读,更多详情请关注应届毕业生考试网。
class person
{
void f1()
{
System.out.println("person f1 is calling !");
}
void f2()
{
f1();
}
}
class student extends person
{
void f1()
{
System.out.println("student f1 is calling! ");
}
void f3()
{
System.out.println("student f3 is calling!");
}
void f4()
{}
}
class Rt20
{
public static void main(String[]args)
{
student s=new student();
call(s);
}
public static void call(person p)/pic/p>
{
if(p instanceof student)/pic/p>
{
student s=(student)p;/pic/p>
s.f1();
s.f2();
s.f3();
}
else
{
p.f1();
p.f2();
}
/pic/pic/p>
/pic/p>
}
}
【Java中对象类型如何进行转换】相关文章:
Java如何完成数据类型转换02-27
java类型的字符转换的方法02-26
Java数据类型转换03-16
Java如何面向对象11-19
Java中float类型的范围及其与十六进制的转换方法12-06
如何理解Java面向对象02-05
Java中创建对象的方式10-16