packagetest81;publicclasstest81{publicstaticvoidmain(String[]args){Students1=newStudent();//报错:Noenclosinginstanceoftypetest81isaccessible.Mustqualifytheallocationwith...
package test81;
public class test81 {
public static void main(String[] args) {
Student s1 = new Student(); //报错:No enclosing instance of type test81 is accessible. Must qualify the allocation with an enclosing instance of type test81 (e.g. x.new A() where x is an instance of test81).
s1.setName("ohno");
s1.setAge(23);
System.out.println(s1.getName()+"...."+s1.getAge());
s1.eat();
s1.study();
System.out.println("..............................................");
Student s2 = new Student();
s2.setName("nino");
s2.setAge(20);
System.out.println(s2.getName()+"...."+s2.getAge());
s2.eat();
s2.study();
}
class person{
private String name;
private int age;
public person(){}
public person(String name,int age){
this.name = name;
this.age = 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;
}
public void eat(){
System.out.println("吃饭");
}
}
class Student extends person{
public Student(){}
public Student(String name,int age){
super(name,age);
}
public void study(){
System.out.println("学习");
}
}
}
展开