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 .
作者遇到在Java中将两个类放入同一文件时出现问题,特别是涉及到final关键字不能被子类重写的特性。通过实例解释了如何正确处理这种情况并避免混淆。
2036

被折叠的 条评论
为什么被折叠?



