请问下面代码发生了什么错误?

bo_zhb 2002-09-05 08:44:46
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.io.*;

public interface Product{ //声明接口
static final String MAKER = "My Corp";
static final String PHONE = "555-123-4567";
public int getPrice(int id);
}

public class Shoe implements Product{//实现PRODUCT接口
public int getPrice(int id) { //重载getPrice方法
if (id == 1)
return (5);
else
return(10);
}

public String getMaker(){
return(MAKER);
}
}


public class Store{
static Shoe hightop;
public static void init(){
hightop = new Shoe();
}

public static void main(String argv[]){
init();
getInfo(hightop);
orderInfo(hightop);
}

public static void getInfo(Shoe item){
System.out.println("this Product is made by "+item.MAKER);
System.out.println("it costs $" + item.getPrice(1) + '\n');
}

public static void orderInfo( Product item){
System.out.println("To order from " + item.MAKER + " call " + item.PHONE + ".");
System.out.println("Each item costs $" + item.getPrice(1));
}
}
...全文
27 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
impeng 2002-09-06
  • 打赏
  • 举报
回复
你的interface和shoe类都不应该是public的(假设文件名是Store.java)

在一个java文件中,只能有一个public类,你的java文件必须以这个类的名称命名。

换句话说,每个public类都应当放置在单独的java文件中。
CatLuDn 2002-09-06
  • 打赏
  • 举报
回复
一楼的不错,public类一个文件中只能又一个..
signboy 2002-09-05
  • 打赏
  • 举报
回复
出什么错呀?
zwzhero 2002-09-05
  • 打赏
  • 举报
回复
最明显的一点是不能同时有两个public 类!

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧