java继承小问题,请求帮忙
import java.applet.*;import java.awt.*;
class area{
double f(double r){
return 3.14*r*r;
}
double g(double x,double y){
return 0.5*x*y;
}
}
class circle extends area{
double f(double r){
return 3.14*2.0*r;
}
}
public class PolyMorphism_Example1 extends Applet{
area obj;
circle cir;
public void init(){
obj=new area();
cir=new circle();
}
public void paint(Graphics g){
g.drawString("圆的面积:"+obj.f(5.0),5,20);
g.drawString("圆的周长:"+cir.f(5.0),5,40);
g.drawString("三角形的面积:"+cir.g(2.0,8.0),5,60);
}
}
为什么只出面积,其他的没出,谢谢!
----------------解决方案--------------------------------------------------------
你的main()方法呢?
没法看啊
----------------解决方案--------------------------------------------------------
。
----------------解决方案--------------------------------------------------------
没什么问题啊
----------------解决方案--------------------------------------------------------
这个程序是APPLET, 不用main()方法
运行没问题,但类名首字母要大写
----------------解决方案--------------------------------------------------------
java.lang.NoClassDefFoundError: area (wrong name: Area)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at Poly.init(Poly.java:20)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
这是我的错误提示
----------------解决方案--------------------------------------------------------
我用的是eclipse
----------------解决方案--------------------------------------------------------
大小写名称要统一, area 与Area是不同的变量
----------------解决方案--------------------------------------------------------
没有main()怎么出结果啊
----------------解决方案--------------------------------------------------------