java 新手提问

Rookiekk 2017-11-21 05:29:55
import java.util.*;

public class Welcome {
public static void main(String[] args) {
new Person().printPerson();//这两行为什么会错
new Student().printPerson();

}
class Student extends Person{
@Override
public String getInfo(){
return "student";
}
}
class Person{
public String getInfo(){
return "person";
}
public void printPerson(){
System.out.println(getInfo());
}
}
}

为什么会错呢。我是按书上打上去的
另外我换成这些之后还是不对
Person p = new Person();
Student s = new Student();
p.printPerson();
s.printPerson();
错误原因都是这些
No enclosing instance of type Welcome is accessible. Must qualify the allocation with an enclosing instance of type Welcome (e.g. x.new A()
where x is an instance of Welcome).
...全文
115 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
李德胜1995 2017-11-21
  • 打赏
  • 举报
回复
把两个类拉倒外面。。。。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧