//照书上的示例抄下来,编译错误,但我又找不出误,急急急........
我反复检查了好几遍也没有发现什么错误>
难道是我的JAVA解释程序有误,请各位帮我运行一下,如果在你们的机器上运行正常,
有可能是我的机器毛病了.谢谢各位!!!!!!!!!!!!!!!!!!
public class Person4
{
static int count=0;
protected String name;
protected int age;
public Person4(String n1,int a1)
{
this.name=n1;
this.age=a1;
this.count++;
}
public int olderthen(Person4 b)
{
Person4 a=this;
return a.age-b.age;
}
public void print()
{
System.out.print(this.getClass().getName()+ " ");
System.out.print("count="+this.count+" ");
System.out.println(" "+this.name+","+this.age); 
}
class Student4 extends Person4
    {
protected String dept;
Student4(String n1,int a1,String d1)
{
super(n1,a1);
dept=d1;
}
}
public static void main(String args[])
{
Person4 p1=new Person4("李大广",21);
p1.print();
Student4 s1=new Student4("陈小瑞",19,"计算机系");//这一行提示出错
s1.print();
System.out.println("年龄差= " + p1.olderthen(s1));
    }
}

解决方案 »

  1.   

    public class Person4
    {
    static int count=0;
    protected String name;
    protected int age;
    public Person4(String n1,int a1)
    {
    this.name=n1;
    this.age=a1;
    this.count++;
    }
    public int olderthen(Person4 b)
    {
    Person4 a=this;
    return a.age-b.age;
    }
    public void print()
    {
    System.out.print(this.getClass().getName()+ " ");
    System.out.print("count="+this.count+" ");
    System.out.println(" "+this.name+","+this.age); 
    } } 
    class Student4 extends Person4
        {
    protected String dept;
    Student4(String n1,int a1,String d1)
    {
    super(n1,a1);
    dept=d1;
    }
    }
    public static void main(String args[])
    {
    Person4 p1=new Person4("李大广",21);
    p1.print();
    Student4 s1=new Student4("陈小瑞",19,"计算机系");//这一行提示出错
    s1.print();
    System.out.println("年龄差= " + p1.olderthen(s1));
        }
    }
    少了一个大括号,再试试
      

  2.   

    太谢谢你了,
    谢谢大恩人,马上给分
    真是我的好老师,
    谢谢你.
    唉,顺便说一下,自学java的确是令人头疼的一件事情.唉,没办法,现在社会竞争那么大.
    只学习一门语言,还不行.
    呜呜,再坚持吧.
      

  3.   

    public class Person4
    {
    static int count=0;
    protected String name;
    protected int age;
    public Person4(String n1,int a1)
    {
    this.name=n1;
    this.age=a1;
    this.count++;
    }
    public int olderthen(Person4 b)
    {
    Person4 a=this;
    return a.age-b.age;
    }
    public void print()
    {
    System.out.print(this.getClass().getName()+ " ");
    System.out.print("count="+this.count+" ");
    System.out.println(" "+this.name+","+this.age); 
    }
    }
    class Student4 extends Person4
        {
    protected String dept;
    Student4(String n1,int a1,String d1)
    {
    super(n1,a1);
    dept=d1;
    }
    public static void main(String args[])
    {
    Person4 p1=new Person4("李大广",21);
    p1.print();
    Student4 s1=new Student4("陈小瑞",19,"计算机系");//这一行提示出错
    s1.print();
    System.out.println("年龄差= " + p1.olderthen(s1));
        }
     }
    还有一个,下面多了一个大括号,刚没在意,不好意思