AI写作智能体 自主规划任务,支持联网查询和网页读取,多模态高效创作各类分析报告、商业计划、营销方案、教学内容等。 广告
## 包装类 **课堂代码:** ~~~java package com.dodoke.demo3; /** * 定义抽象类 * 在抽象类中,可以没有抽象方法 * 但是如果在一个类中有抽象方法,那么该类必须用abstract修饰 * @author 一教室 * */ public abstract class Person { public String name; public int age; public int sex; public static String test = "2";//static 修饰的静态变量也能被继承 /** * The abstract method say in type Person can only be defined by an abstract class * 如果在一个类中定义抽象方法,那么该类必须首先定义为抽象类 * 抽象方法是没有大括号和方法体的 */ public abstract void say(); //The abstract method talk in type Person can only set a visibility modifier, one of public or protected //private abstract void talk();错误的,不能用private修饰 //abstract void talk();正确的,可以用default修饰 //public abstract static void tell();错误的,不能用static修饰 public Person(String name, int age, int sex) { super(); this.name = name; this.age = age; this.sex = sex; } public Person() { super(); } } ~~~ ~~~java package com.dodoke.demo3; /** * The type GaoJunNan must implement the inherited abstract method Person.talk() * 当一个类继承了抽象类,就必须去重写抽象类中的抽象方法 * @author 一教室 * */ public class GaoJunNan extends Person{ private boolean isMarry; public boolean isMarry() { return isMarry; } public void setMarry(boolean isMarry) { this.isMarry = isMarry; } public GaoJunNan() { super(); } public GaoJunNan(String name, int age, int sex, boolean isMarry) { super(name, age, sex); this.isMarry = isMarry; } public static void main(String[] args) { //Person per = new Person();无法实例化抽象类person GaoJunNan gjn = new GaoJunNan("高俊楠", 24, 1, false); System.out.println(gjn.name); System.out.println(GaoJunNan.test); gjn.say(); } /** * 强制性的要求重写抽象方法 */ @Override public void say() { System.out.println("高俊楠说中文"); } } ~~~