package helloworldapp;
public class first
{
class J_Employee
{
public int m_workYear;
public J_Employee()
{
m_workYear = 1;
}
}
public class J_Teacher extends J_Employee
{
public int m_classHour;
public J_Teacher()
{
m_classHour = 96;
}
public void mb_printInfo()
{
System.out.println("该教师的工作年限为"+m_workYear);
System.out.println("该教师的授课课时为"+m_classHour);
}
public static void main(String args[])
{
J_Teacher tom = new J_Teacher();
tom.mb_printInfo();
}
}
}
书本的例子错了么?? 如果将main放到类外,也不行,求解决方法!!
Java 类
------解决方案--------------------
楼主吧main移出来,然后改成下面这样:
public static void main(String args[])
{
PolymorphismTest pltt=new PolymorphismTest();
PolymorphismTest.J_Teacher tom=pltt.new J_Teacher();
tom.mb_printInfo();
}
这样应该很清楚知道为什么错了吧?