java的class建错_java创建对象的时候报错了,不知道哪里错了。。。。。。

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("学习");

}

}

}

展开

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值