【文件属性】:
文件名称:final修饰符与类型转化
文件大小:30KB
文件格式:DOC
更新时间:2012-11-01 03:19:30
final修饰符与类型转化
final修饰符与类型转化
类型转换是java编程中比较常见的一种操作,特别是基本数据类型之间的转换,如long型转化为int型,int转化为long等等。
类型的转化可以分成两类:强制转化与自动转化,例如long i=1;这个就叫自动转化,而int i=(long)1L,就是强制转化,这里我们主要讨论类对象之间的转化,还是以下面的代码为例:
public class PolymorphicTest {
public PolymorphicTest() {
}
public void setName(String n){
this.name=n;
System.out.println(“在父类中”);
}
public String getName(){
return this.name;
}
private String name;
}
public class PolymorphicChild extends PolymorphicTest {
public void setArea(String a){
this.area=a;
}
public String getArea(){
return this.area;
}
//public void setName(String n){
// super(“n”);
// System.out.pirngln(“在子类中”);
// }
public static void main(String[] args) {
PolymorphicChild child=new PolymorphicChild();
PolymorphicTest test[]=new PolymorphicTest[2];
test[0]=child;
PolymorphicChild cast=(PolymorphicChild)test[0];
test[0].setName(“zhukai”);
test[1]=new PolymorphicTest();
}
private String area;
}