静态内部抽象类可以被继承。

public class testfather {
public static void main(String[] args) {
person.talk2 a = new newtalk();
a.get();
person person1 = new student("alice", 20, "女");
System.out.println(person1.talk());
/* person person2 = new person(); */ // 抽象类不能调用

}
}

abstract class person {
String name;
int age;
String sex;

public person(String name, int age, String sex) // 等会试一下能否调用构造方法
{
this.name = name;
this.age = age;
this.sex = sex;
}

public abstract String talk(); // 声明一个抽象方法,可以不写其方法内容

static abstract class talk2 // 内部抽象类,静态方法 可以被继承
{
public abstract void get();
}
}

class newtalk extends person.talk2 {                  //验证内部静态类(相当于一个独立的抽象类)的继承
public void get() {
System.out.println("人物信息: ");
}
}

class student extends person {
public student(String name, int age, String sex) {
super(name, age, sex);      //继承父类构造方法
}

public String talk() {
return "姓名:" + name + " 年龄:" + age + " 性别:" + sex;
}
}

相关文章:

  • 2022-12-23
  • 2021-10-06
  • 2022-01-02
  • 2021-11-23
  • 2021-12-20
  • 2022-12-23
  • 2021-10-12
猜你喜欢
  • 2022-12-23
  • 2021-05-06
  • 2021-11-28
  • 2021-09-18
  • 2021-05-04
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案