java找错

[复制链接]
查看11 | 回复4 | 2010-5-18 09:00:58 | 显示全部楼层 |阅读模式
public class person1
{
static int count=0;
protected String name;
protected int age;
public person1(String n1,int a1)
{
this.name=n1;
this.age=a1;
this.count++;
}
public int oldthen(person1 yaoming)
{
person1 pan=this;
return pan.age-yaoming.age;
}
public void print()
{
System.out.println("count="+this.count+" name="+this.name+" age="+this.age);
}

}
public student extends person1
{
protected String xibie;
public student(String n1,int a1,String xd)
{
super(n1,a1);
xibie="xd";
}
public static void main (String[] args)
{
person1 p1=new person1("姚明",25);
p1.print();
student t1=new student("PP",28,"计算机系");
t1.print();
System.out.println("年龄差"+p1.olderthen(t1));
}
}
下面是出错提示:
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:31: 需要为 class、interface 或 enum
public student extends person1

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:34: 需要为 class、interface 或 enum

public student(String n1,int a1,String xd)

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:37: 需要为 class、interface 或 enum

xibie="xd";

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:38: 需要为 class、interface 或 enum

}

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:39: 需要为 class、interface 或 enum

public static void main (String[] args)

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:41: 非法字符: \65292

person1 p1=new person1("姚明",25);

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:42: 需要为 class、interface 或 enum

p1.print();

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:43: 需要为 class、interface 或 enum

student t1=new student("PP",28,"计算机系");

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:43: 非法字符: \65292

student t1=new student("PP",28,"计算机系");

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:43: 非法字符: \65292

student t1=new student("PP",28,"计算机系");

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:44: 需要为 class、interface 或 enum

t1.print();

^
C:\Users\wei\Documents\JCreator Pro\MyProjects\person1\src\person1.java:46: 需要为 class、interface 或 enum

}

^
12 错误
Process complet

求高人指点

回复

使用道具 举报

千问 | 2010-5-18 09:00:58 | 显示全部楼层
public class person1 { static int count = 0; protected String name; protected int age; public person1(String n1, int a1) {this.name = n1;this.age = a1;this.count++; } public int oldthen(person1 yaoming) {person1 pan = this;return pan.age - yaoming.age; } public void print() {System.o
回复

使用道具 举报

千问 | 2010-5-18 09:00:58 | 显示全部楼层
一个类里面是不允许有两个public class的,在说了,我看是语法错误吧,是不是少了括号了,自己仔细看看吧,只有自己找到了问题才会提升,在说了,你把类名首字母大写,这样规范点
回复

使用道具 举报

千问 | 2010-5-18 09:00:58 | 显示全部楼层
public student extends person1这里应该加上 classpublic class student extends person1
回复

使用道具 举报

千问 | 2010-5-18 09:00:58 | 显示全部楼层
这是什么啊 ?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行