interface Contents //1行
{
int value();
}
interface Destination
{
String readLabel();
}
class Goods
{
private class Content implements Contents
{
private int i = 11;
public int value()
{
return i;
}
}
protected class GDestination implements Destination
{
private String label;
private GDestination(String whereTo)
{
label = whereTo;
}
public String readLabel()
{
return label;
}
}
public Destination dest(String s)
{
return new GDestination(s);
}
public Contents cont()
{
return new Content();
}
}
class TestGoods
{
public static void main(String[] args)
{
Goods p = new Goods();
Contents c = p.cont();
Destination d = p.dest("Beijing");
}
}
/*
请问:
1、 请问,为什么不能在第一行的行首加public,因为如果加上了public,则编译器显示如下错误:
-------------------------
Inner.java:1: 类 Contents 是公共的,应在名为 Contents.java 的文件中声明
public interface Contents
^
1 错误
-------------------------
Contents 是借口,不是类啊?
2、我发现一个程序当中只能有一个public类,并且该程序的名字必须和该public类的类名相同,为什么 请诸位指教
*/
{
int value();
}
interface Destination
{
String readLabel();
}
class Goods
{
private class Content implements Contents
{
private int i = 11;
public int value()
{
return i;
}
}
protected class GDestination implements Destination
{
private String label;
private GDestination(String whereTo)
{
label = whereTo;
}
public String readLabel()
{
return label;
}
}
public Destination dest(String s)
{
return new GDestination(s);
}
public Contents cont()
{
return new Content();
}
}
class TestGoods
{
public static void main(String[] args)
{
Goods p = new Goods();
Contents c = p.cont();
Destination d = p.dest("Beijing");
}
}
/*
请问:
1、 请问,为什么不能在第一行的行首加public,因为如果加上了public,则编译器显示如下错误:
-------------------------
Inner.java:1: 类 Contents 是公共的,应在名为 Contents.java 的文件中声明
public interface Contents
^
1 错误
-------------------------
Contents 是借口,不是类啊?
2、我发现一个程序当中只能有一个public类,并且该程序的名字必须和该public类的类名相同,为什么 请诸位指教
*/
楼主【xjyr】截止到2008-06-24 11:35:26的历史汇总数据(不包括此帖):
发帖数:58 发帖分:1160
结贴数:8 结贴分:160
未结数:50 未结分:1000
结贴率:13.79 % 结分率:13.79 %
因为是java规定的~~~
而且不是一个程序中~~应该是一个java文件中
问题2、第二个是java的约定俗成,就好比是main方法被定义成可以执行一样