//照书上的示例抄下来,编译错误,但我又找不出误,急急急........
我反复检查了好几遍也没有发现什么错误>
难道是我的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));
}
}
我反复检查了好几遍也没有发现什么错误>
难道是我的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));
}
}
解决方案 »
- JFrame如何去掉任务栏的按钮?
- 正则表达式 匹配某一网页内容里的一组字符串中的数字 比如 珠宝/钻石/翡翠/黄金(17048) 怎么把这个数字拿出来
- 如何获得jtable中的数据
- 各位学习JAVA的朋友们``你们现在都用JAVA来做些什么小程序``举一个15分`重复不算`谢谢!
- 很奇怪的java、oracle中文问题
- 如果让一个JTable的一个单元格处于编辑状态呢?
- 想研究一下,对JXTA有了解的进来谈谈!欢迎讨论,提供资料!!
- java 接口
- 请介绍几本有关JBuilder的入门级好书。
- 通配符的匹配很全面, 但无法找到元素 'context:annotation-config' 的声明。
- 一个全英文的JAVA题,有人会做吗??
- 有意思的题哦!
{
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));
}
}
少了一个大括号,再试试
谢谢大恩人,马上给分
真是我的好老师,
谢谢你.
唉,顺便说一下,自学java的确是令人头疼的一件事情.唉,没办法,现在社会竞争那么大.
只学习一门语言,还不行.
呜呜,再坚持吧.
{
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));
}
}
还有一个,下面多了一个大括号,刚没在意,不好意思