java小程序修改

[复制链接]
查看11 | 回复4 | 2010-5-20 12:27:49 | 显示全部楼层 |阅读模式
首先你这个程序有很多逻辑问题,语法错误也不少,给你改了一个,语法错误没有了,不知道符合你的逻辑不class Person3 {public void eat(Apple apple) { Apple peeled = Peeler.getpeel(apple); System.out.println("Yummy");} } class Peeler {static Apple getpeel(Apple apple) { return apple;} } class Apple {Apple getprrled() { return Peeler.getpeel(this);}//这是给peel方法传递一个Apple对象.} public class PassingThis {public static void main(String[] args){new Person3().eat(new Apple());}//这句话表示调用Person类的方法eat并传递一个Apple类的
//对象(这个对象的引用给了apple) }
回复

使用道具 举报

千问 | 2010-5-20 12:27:49 | 显示全部楼层
class Person { public void eat(Apple apple) {Peeler peel = apple.getpeel();System.out.println("Yummy"); }}class Peeler { }class Apple { Peeler getpeel() {return new Peeler(); }}public class PassingThis { public static void main(String[] args) {new Person().eat(new Apple()); }// 这句话表示调用Person类的方法eat并传递一个Apple类的 // 对象(这个对象的引用给了apple)}
回复

使用道具 举报

千问 | 2010-5-20 12:27:49 | 显示全部楼层
问题很严重,呵呵class Person3 { public void eat(Apple apple) {Apple peeled = apple.getpeel();System.out.println("Yummy"); }}class Peeler { static Apple getpeel(Apple apple) {return apple; }}class Apple { Apple getprrled() {return Peeler.getpeel(this); }//这是给peel方法传递一个Apple对象. }public class PassingThis { public static void main(String[] args){ new.Person3().eat(new Apple()); }//这句话表示调用Person类的方法eat并传递一个Apple类的 //对象(这个对象的引用给了apple)}有问题再问我楼上的瞎说,构造函数默认是有的
回复

使用道具 举报

千问 | 2010-5-20 12:27:49 | 显示全部楼层
你的类都没有构造函数啊
回复

使用道具 举报

千问 | 2010-5-20 12:27:49 | 显示全部楼层
好乱的东东。。。。。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行