/**
* 红色标注错误地方
*/public class Persont {
private String name;
private int age;
public void setName(String name){
this.name=name;
}
public void setAge(int age)
{
this.age=age;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
class Student extends Persont{
private String school;
public String getSchool(){
return school;
}
public void setSchool(String school){
this.school=school;
}
}
/**
* @param args
*/
public static void main(String[] args)
{
Student student = new Student(); student.setName("weijin");
student.setAge(18);
student.setSchool("seles");
System.out.print(student.getName());
System.out.print(student.getAge());
System.out.print(student.getSchool());
// TODO Auto-generated method stub }}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type Persont is accessible. Must qualify the allocation with an enclosing instance of type Persont (e.g. x.new A() where x is an instance of Persont). at Persont.main(Persont.java:43)
* 红色标注错误地方
*/public class Persont {
private String name;
private int age;
public void setName(String name){
this.name=name;
}
public void setAge(int age)
{
this.age=age;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
class Student extends Persont{
private String school;
public String getSchool(){
return school;
}
public void setSchool(String school){
this.school=school;
}
}
/**
* @param args
*/
public static void main(String[] args)
{
Student student = new Student(); student.setName("weijin");
student.setAge(18);
student.setSchool("seles");
System.out.print(student.getName());
System.out.print(student.getAge());
System.out.print(student.getSchool());
// TODO Auto-generated method stub }}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type Persont is accessible. Must qualify the allocation with an enclosing instance of type Persont (e.g. x.new A() where x is an instance of Persont). at Persont.main(Persont.java:43)
class Student extends Persont{
private String school; public String getSchool(){
return school; } public void setSchool(String school){
this.school=school;
} }
放到代码的最外边}