class Person{
private String name;
private int age;
public void  setName(String name){
this.name=name;
}
public String getName(){
return name;

}
public void  setAge(int age){
this.age=age;

}
public int getAge(){
return age;
}
}
class Student extends Person{
private String school;
public void setSchool(String school){
this.school=school;
}
public String getSchool(){
return school;
}

}
public class TestPerson{
public static void main (String arg[]){
Student student=new Student();
Student.setName("jim");
Student.setAge(78);
Student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
}
}

解决方案 »

  1.   

    change below code
    Student.setName("jim"); 
    Student.setAge(78); 
    Student.setSchool("home"); to 
    student.setName("jim"); 
    student.setAge(78); 
    student.setSchool("home"); 
      

  2.   

    class Person{ 
    private static String name; 
    private static int age; 
    public static void  setName(String n){ 
    name=n; 

    public String getName(){ 
    return name;  } 
    public static void  setAge(int a){ 
    age=a;  } 
    public int getAge(){ 
    return age; 


    class Student extends Person{ 
    private static String school; 
    public static void setSchool(String s){ 
    school=s; 

    public String getSchool(){ 
    return school; 
    } } 
    public class TestPerson{ 
    public static void main (String arg[]){ 
    Student student=new Student(); 
    Student.setName("jim"); 
    Student.setAge(78); 
    Student.setSchool("home"); 
    System.out.println(student.getName()); 
    System.out.println(student.getAge()); 
    System.out.println(student.getSchool()); 

    }
      

  3.   

    class Person{ 
    private static String name; 
    private static int age; 
    public static void  setName(String n){ 
    name=n; 

    public String getName(){ 
    return name;  } 
    public static void  setAge(int a){ 
    age=a;  } 
    public int getAge(){ 
    return age; 


    class Student extends Person{ 
    private static String school; 
    public static void setSchool(String s){ 
    school=s; 

    public String getSchool(){ 
    return school; 
    } } 
    public class TestPerson{ 
    public static void main (String arg[]){ 
    Student student=new Student(); 
    Student.setName("jim"); 
    Student.setAge(78); 
    Student.setSchool("home"); 
    System.out.println(student.getName()); 
    System.out.println(student.getAge()); 
    System.out.println(student.getSchool()); 

    }
      

  4.   

    class Person{ 
    private static String name; 
    private static int age; 
    public static void  setName(String n){ 
    name=n; 

    public String getName(){ 
    return name;  } 
    public static void  setAge(int a){ 
    age=a;  } 
    public int getAge(){ 
    return age; 


    class Student extends Person{ 
    private static String school; 
    public static void setSchool(String s){ 
    school=s; 

    public String getSchool(){ 
    return school; 
    } } 
    public class TestPerson{ 
    public static void main (String arg[]){ 
    Student student=new Student(); 
    Student.setName("jim"); 
    Student.setAge(78); 
    Student.setSchool("home"); 
    System.out.println(student.getName()); 
    System.out.println(student.getAge()); 
    System.out.println(student.getSchool()); 

    }
      

  5.   

    public class TestPerson{ 
    public static void main (String arg[]){ 
    Student student=new Student(); 
    Student.setName("jim"); 
    Student.setAge(78); 
    Student.setSchool("home"); 
    System.out.println(student.getName()); 
    System.out.println(student.getAge()); 
    System.out.println(student.getSchool()); 

    }student.setName("jim"); 
    student.setAge(78); 
    student.setSchool("home");  用定义的对象名student而不是class名
      

  6.   

    你看仔细啊,Student是class啊,不是具体的对象,应该是student
      

  7.   

    我帮你整理了一下.
    public class TestPerson {

    private String aaaa;

    public static void main (String arg[]){  Student student; 
    TestPerson tp=new TestPerson();//实例化TestPerson类,以用来调用它里面的内部类Studnet
    student=tp.new Student();//因为Studnet是TestPerson的一个内部类,想实例化一个Student对象你必须在实例化好的外部类中调用.
    student.setName("jim"); 
    student.setAge(78); 
    student.setSchool("home"); 
    System.out.println(student.getName()); 
    System.out.println(student.getAge()); 
    System.out.println(student.getSchool()); 
    } class Person {
    private String name; private int age; public void setName(String name) {
    this.name = name;
    } public String getName() {
    return name; } public void setAge(int age) {
    this.age = age; } public int getAge() {
    return age;
    }
    } class Student extends Person {
    private String school; public void setSchool(String school) {
    this.school = school;
    } public String getSchool() {
    return school;
    } }}你试一下看看是出现结果了.
      

  8.   

    public class TestPerson { private String aaaa; public static void main (String arg[]){  Student student;  
    TestPerson tp=new TestPerson();//实例化TestPerson类,以用来调用它里面的内部类Studnet 
    student=tp.new Student();//因为Studnet是TestPerson的一个内部类,想实例化一个Student对象你必须在实例化好的外部类中调用.
    student.setName("jim");  
    student.setAge(78);  
    student.setSchool("home");  
    System.out.println(student.getName());  
    System.out.println(student.getAge());  
    System.out.println(student.getSchool());  
    } class Person { 
    private String name; private int age; public void setName(String name) { 
    this.name = name; 
    } public String getName() { 
    return name; } public void setAge(int age) { 
    this.age = age; } public int getAge() { 
    return age; 

    } class Student extends Person { 
    private String school; public void setSchool(String school) { 
    this.school = school; 
    } public String getSchool() { 
    return school; 
    } } } 刚才红色字后面的在下一行,有些错位.
    不好意思.
    呵呵@@@@
      

  9.   

    class Person {
        private String name;
        private int age;    public void setName(String name) {
            this.name = name;
        }    public String getName() {
            return name;    }    public void setAge(int age) {
            this.age = age;    }    public int getAge() {
            return age;
        }
    }class Student extends Person {
        private String school;    public void setSchool(String school) {
            this.school = school;
        }    public String getSchool() {
            return school;
        }}public class TestPerson {
        public static void main(String arg[]) {
            Student student = new Student();
            student.setName("jim");  // 修改Student为student,由于Student不是static类型的,所以不能直接调用类中的方法,因此会编译错误
            student.setAge(78);      // 在前一行实例化了一个Student对象,因此,应该对这个对象进行赋值、取值操作。
            student.setSchool("home");
            System.out.println(student.getName());
            System.out.println(student.getAge());
            System.out.println(student.getSchool());
        }
    }
      

  10.   

    有点要补充的,我这说Student不是static类型是说你调用的setName、setAge、setSchool不是static的,所以不能直接调用,必须要实例出对象才能调用。
      

  11.   

    public void  setName(String name){ 
    this.name=name; 

    public void  setAge(int age){ 
    this.age=age; } 
    //以上两个方法使用错误,换成构造函数去实现他们
    public Person(String name,int age){
    this.name = name;
    this.age = age;}
    Person p = new Person("mike",11);//建立对象把属性传给构造函数执行初始化操作,构造函数就是用来初始化对象的 
    public void setSchool(String school){ 
    this.school=school; 
    } public Student(String name,int age,String school){//第二个类的构造函数必须带上他父类的成员然后加上自己类的成员super(name,age);//super()方法自动调用父类中的构造函数以实现初始化操作
    this.school = school;
    }Student stu = new Student("mike",11,"bgedu");//建立对象