Topic: 关于java继承的问题? |
Print this page |
1.关于java继承的问题? | Copy to clipboard |
Posted by: 土妞 Posted on: 2005-04-21 20:53 class Calculator { int add(int x,int y) {return x+y;} } class NewCalculator extends Calculator { double add(double x,double y) {return x+y;} } public Test {public static void main(String[] args) {Calculator c=new Calculator(); NewCalculator nc=new NewCalculator(); c.add(10,20); nc.add(10,20); //这一句出错 } } 这里应该构成了方法的重载,可是为什么出错呢? |
2.Re:关于java继承的问题? [Re: 土妞] | Copy to clipboard |
Posted by: why Posted on: 2005-04-21 21:40 I don't see any problem with overloading the add method ... okay, here's an unrelated issue: public class Test What's the compilation error you received? Are you sure it's really 这一句出错? |
3.Re:关于java继承的问题? [Re: 土妞] | Copy to clipboard |
Posted by: kaiserlew Posted on: 2005-04-22 01:05 土妞 wrote: add方法是有返回值的 int a=c.add(10,20); double b=nc.add(10,20); System.out.print(a+" "+b+" "); |
4.Re:关于java继承的问题? [Re: 土妞] | Copy to clipboard |
Posted by: wddodo Posted on: 2005-04-22 08:37 public " class" Test |
5.Re:关于java继承的问题? [Re: 土妞] | Copy to clipboard |
Posted by: 土妞 Posted on: 2005-04-23 15:45 后来我发现,在jdk1.3.0下编译通不过,在jdk1.4下却能运行.难道是jdk版本的问题? |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |