接口父类变量引用指向子类
package com.udppacket;
public class demo1111 {
public static void main(String[] args) {
Runnable a = new stu2("张三");
a.run();
stu2 b =(stu2) a;
b.getName();
}
}
class stu {
String name;
public stu(String name) {
super();
this.name = name;
}
}
class stu2 extends stu implements Runnable{
public stu2(String name) {
super(name);
}
public void getName(){
System.out.println(name);
}
@Override
public void run() {
System.out.println(name);
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
posted on 2015-05-04 10:49 MrCharles在cnblogs 阅读(215) 评论(0) 编辑 收藏 举报