这个java程序中提示缺少标示符
publicclassPerson{privateStringname;privateStringsex;privateintage;publicvoidproduce(...
public class Person{
private String name;
private String sex;
private int age;
public void produce(){
System.out.println("name is"+this.name);
System.out.println("sex is"+this.sex);
System.out.println("age is"+this.age);
}
public Person(String name,String sex,int age){
this.name=name;
this.age=age;
this.sex=sex;
}
public static void main(String args[]){
Person person1=new Person("张三","男",22);
person1.produce();
Person person2=new Person("李红","女",27);
person2.produce();
Person person3=new Person("鹏鹏","男",26);
person3.produce();
}
public String getName(){return name;}
public void setName(){this.name=name;}
public String getSex(){return sex;}
public void setSex(){this.sex=this.sex;}
public int getAge(){return age;}
public void setAge(){this.age=age;}
class Student extends Person{
private double StudentID;
public double getStudentID(){return StudentID;}
public void setStudentID(){this.StudentID=StudentID;}
public Student(String name,String sex,int age,double StudentID )
{
super(name,sex,age);
this.StudentID=StudentID;
}
public void produce(){
System.out.println(name+" "+sex+" "+age+" "+this.StudentID);
}
Student student1=new Student("王晓","男",23,2008001);
student1.produce.()
}
}
提示是这样的 Person:java:47:(需要标示符)
student1.produce.() 展开
private String name;
private String sex;
private int age;
public void produce(){
System.out.println("name is"+this.name);
System.out.println("sex is"+this.sex);
System.out.println("age is"+this.age);
}
public Person(String name,String sex,int age){
this.name=name;
this.age=age;
this.sex=sex;
}
public static void main(String args[]){
Person person1=new Person("张三","男",22);
person1.produce();
Person person2=new Person("李红","女",27);
person2.produce();
Person person3=new Person("鹏鹏","男",26);
person3.produce();
}
public String getName(){return name;}
public void setName(){this.name=name;}
public String getSex(){return sex;}
public void setSex(){this.sex=this.sex;}
public int getAge(){return age;}
public void setAge(){this.age=age;}
class Student extends Person{
private double StudentID;
public double getStudentID(){return StudentID;}
public void setStudentID(){this.StudentID=StudentID;}
public Student(String name,String sex,int age,double StudentID )
{
super(name,sex,age);
this.StudentID=StudentID;
}
public void produce(){
System.out.println(name+" "+sex+" "+age+" "+this.StudentID);
}
Student student1=new Student("王晓","男",23,2008001);
student1.produce.()
}
}
提示是这样的 Person:java:47:(需要标示符)
student1.produce.() 展开
5个回答
展开全部
首先我告诉你为什么会出错,你的程序我没有细看,所以不知道这句话的功能是什么。
class Student extends Person{}这个是写在Person里的一个内部类,既然是类,那咱们就知道了,java的类里面是只能有成员变量和成员方法的,不可以有像student1.produce.()这样的语句的,你可以写一个方法,在方法里调用,然后再调用这个方法就可以
class Student extends Person{}这个是写在Person里的一个内部类,既然是类,那咱们就知道了,java的类里面是只能有成员变量和成员方法的,不可以有像student1.produce.()这样的语句的,你可以写一个方法,在方法里调用,然后再调用这个方法就可以
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看了你的程序,大概明白你要实现什么了。我改了一下你看一下:
public class Person{
private String name;
private String sex;
private int age;
public void produce(){
System.out.println("name is"+this.name);
System.out.println("sex is"+this.sex);
System.out.println("age is"+this.age);
}
public Person(String name,String sex,int age){
this.name=name;
this.age=age;
this.sex=sex;
}
public static void main(String args[]){
Person person1=new Person("张三","男",22);
person1.produce();
Person person2=new Person("李红","女",27);
person2.produce();
Person person3=new Person("鹏鹏","男",26);
person3.produce();
Student student1=new Student("王晓","男",23,2008001);
student1.produce.();
}
public String getName(){return name;}
public void setName(){this.name=name;}
public String getSex(){return sex;}
public void setSex(){this.sex=this.sex;}
public int getAge(){return age;}
public void setAge(){this.age=age;}
}
class Student extends Person{
private double StudentID;
public double getStudentID(){return StudentID;}
public void setStudentID(){this.StudentID=StudentID;}
public Student(String name,String sex,int age,double StudentID )
{
super(name,sex,age);
this.StudentID=StudentID;
}
public void produce(){
System.out.println(name+" "+sex+" "+age+" "+this.StudentID);
}
}
public class Person{
private String name;
private String sex;
private int age;
public void produce(){
System.out.println("name is"+this.name);
System.out.println("sex is"+this.sex);
System.out.println("age is"+this.age);
}
public Person(String name,String sex,int age){
this.name=name;
this.age=age;
this.sex=sex;
}
public static void main(String args[]){
Person person1=new Person("张三","男",22);
person1.produce();
Person person2=new Person("李红","女",27);
person2.produce();
Person person3=new Person("鹏鹏","男",26);
person3.produce();
Student student1=new Student("王晓","男",23,2008001);
student1.produce.();
}
public String getName(){return name;}
public void setName(){this.name=name;}
public String getSex(){return sex;}
public void setSex(){this.sex=this.sex;}
public int getAge(){return age;}
public void setAge(){this.age=age;}
}
class Student extends Person{
private double StudentID;
public double getStudentID(){return StudentID;}
public void setStudentID(){this.StudentID=StudentID;}
public Student(String name,String sex,int age,double StudentID )
{
super(name,sex,age);
this.StudentID=StudentID;
}
public void produce(){
System.out.println(name+" "+sex+" "+age+" "+this.StudentID);
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
student1.produce.()
改成
student1.produce();
试试
改成
student1.produce();
试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
student1.produce.() 后面的分号呢????
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
分号来???好像没有分号。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询