您的位置:首页 > 编程语言 > Java开发

Two classes cannot be put in a .java file

2011-10-01 19:19 393 查看
Twoclassescannotbeputin
a.java file.
Forexample
:
publicclassFinalTest
{
String
color="yellow";
 
publicvoidgetMes()
{
System.out.println("parent
class variable of color: "+color);
}
 
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
publicclasstest
extendsFinalTest
{
String color="blue";

publicvoidgetMes()
{
System.out.println("child class variable of color: "+color);
}
 
public
staticvoidmain (String[] args)
{
test t=newtest();
 
t.getMes();
}
}

Thought it's a simply programming ,it took me nearly half an hour to check out where goes wrong.---I put them in a same .java file ,and hadn't create a test.java in the package folder.


PS:A function which is the type of final cannot be rewrite in its child class .
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  class string file function
相关文章推荐