java--抽象类实例(包含静态内部抽象类)

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

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;
}
}

原文地址:https://www.cnblogs.com/2206411193qzb/p/7354404.html