求大神看下 这个JAVA程序怎么不能运行

packagea;publicclassshape{Stringshapetype;publicvoidShape(){System.out.print("Shapeis... package a;
public class shape
{
String shapetype;
public void Shape()
{
System.out.print("Shape is initialized!");
}
public void draw()
{
System.out.print("shape draw () is called");
}
class Circle extends shape
{
public Circle ()
{
System.out.print("circle is initialized");
}
public void draw ()
{
System.out.print("circle draw () is called");
}
}
class Square extends shape
{
public Square ()
{
System.out.print("square is initialized");
}
public void draw ()
{
System.out.print("square draw () is called");
}
}
class Trine extends shape
{
public Trine ()
{
System.out.print("trine is initialized");
}
public void draw ()
{
System.out.print("trine draw () is called");
}
}
public class PolyTest
{
private void foo(shape shape)
{
shape.draw();
}

}
public void main (String [] args )
{
PolyTest polytest=new PolyTest();
Circle circle=new Circle();
Square square=new Square();
Trine trine=new Trine ();
polytest.foo(circle);
polytest.foo(square);
polytest.foo(trine);
}
}
展开
 我来答
xyhjyh
2012-08-17 · TA获得超过117个赞
知道答主
回答量:79
采纳率:100%
帮助的人:55.1万
展开全部
1. main 方法 要加static
public static void main (String [] args )
2. 你的类都是定义在内部的,不能直接访问,改成下面的方式
shape sp = new shape();
PolyTest polytest = sp.new PolyTest();
Circle circle = sp.new Circle();
Square square = sp.new Square();
Trine trine = sp.new Trine();
polytest.foo(circle);
polytest.foo(square);
polytest.foo(trine);
创作者zrb3721
2012-08-17 · TA获得超过709个赞
知道小有建树答主
回答量:543
采纳率:0%
帮助的人:256万
展开全部
main方法加上static
而且都是内部类,使用时要用主类的对象使用
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
lmy_sk521
2012-08-17 · TA获得超过2272个赞
知道小有建树答主
回答量:1330
采纳率:73%
帮助的人:729万
展开全部
改成这样:
public class PolyTest {
private void foo(shape shape) {
shape.draw();
}
public static void main(String[] args) {
PolyTest polytest = new PolyTest();
Circle circle = new Circle();
Square square = new Square();
Trine trine = new Trine();
polytest.foo(circle);
polytest.foo(square);
polytest.foo(trine);
}
}
class shape {
String shapetype;
public void Shape() {
System.out.print("Shape is initialized!");
}
public void draw() {
System.out.print("shape draw () is called");
}
}
class Circle extends shape {
public Circle() {
System.out.print("circle is initialized");
}
public void draw() {
System.out.print("circle draw () is called");
}
}
class Square extends shape {
public Square() {
System.out.print("square is initialized");
}
public void draw() {
System.out.print("square draw () is called");
}
}
class Trine extends shape {
public Trine() {
System.out.print("trine is initialized");
}
public void draw() {
System.out.print("trine draw () is called");
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
简卓利i
2012-08-17
知道答主
回答量:84
采纳率:0%
帮助的人:34.1万
展开全部
public void main (String [] args )
{
PolyTest polytest=new PolyTest();
Circle circle=new Circle(); ---------改成Square rcle=new Circle();
Square square=new Square();
Trine trine=new Trine (); --------- 改成Square trine=new Trine ();
polytest.foo(circle);
polytest.foo(square);
polytest.foo(trine);
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式