java中怎么实现多态??? 在java里重载和覆盖有什么区别吗??能不能给个例程?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public Class1{ public void method1(String a){ ... } public void method2(String a){ ... }}public Class2 extends Class1{ public void method1(String a){ //覆盖 ... } public void method2(int a){ //重载 ... }} 你看看有关向上转型(upcasting)就可以了解点多态了,要直接解释比较不容易懂,找点例程看吧! Java 中所有的函数默认都是虚函数(构造函数与静态函数除外), 可以实现多态: 如下class Test1{ public static void main(String[] args){ Shape shape = new Shape(); shape.draw(); shape = new Sqaure(); shape.draw(); shape = new Circle(); shape.draw(); }}class Shape{ void draw(){ System.out.println("Shape"); }}class Sqaure extends Shape{ void draw(){ System.out.println("Sqaure"); }}class Circle extends Shape{ void draw(){ System.out.println("Circle"); }} 路往哪儿走 eclipse操作快捷键 一个关于nextInt() 的问题 导出oracle出错java.lang.OutOfMemoryError: Java heap space 菜鸟问题 向一个女生示意,遭婉拒,郁闷中 第一次用java,如何快捷学习??? java中怎样实现自定义事件 属于概念不清的一个简单的问题! 日期问题,搞定了我请客 一个double类型如何四舍五入到若干位有效数字 我要创建一个模式对话框,但是......
public void method1(String a){
...
}
public void method2(String a){
...
}
}
public Class2 extends Class1{
public void method1(String a){ //覆盖
...
}
public void method2(int a){ //重载
...
}
}
class Test1{
public static void main(String[] args){
Shape shape = new Shape();
shape.draw();
shape = new Sqaure();
shape.draw();
shape = new Circle();
shape.draw();
}
}class Shape{
void draw(){
System.out.println("Shape");
}
}class Sqaure extends Shape{
void draw(){
System.out.println("Sqaure");
}
}class Circle extends Shape{
void draw(){
System.out.println("Circle");
}
}