封装
1、提高程序的安全性,保护数据
2、隐藏代码的实现细节
3、统一接口
4、提高系统可维护性
继承 只有单继承,没有多继承
777 DQW PUNG
子类中默认调用父类的构造器 super(); 显式调用父类构造器必须在第一行
super
super注意点:
1、super调用父类的构造方法,必须在构造方法的第一个
2、super只能出现在子类的方法或者构造方法中!
3、super和this不能同时调用构造方法
4、this代表本身调用者
5、super代表父类对象的引用
6、没有继承也可以使用
7、super只能在继承条件才可以使用
8、构造方法 this(); 本类的构造
9、super(); 父类的构造
10、不允许递归构造this();
—
static 子类重写父类重写无效 public > protected > default > private 输出不同
A对B重写 输出 相同
多态
Father f = new Son(); 方法的多态 继承关系 方法需要重写 父类引用f执行子类对象new Son()
Static private final没有多态
instanceof 类型转换
Object > People > Student // people是object类和People类,但不是Student类,doctor类
Object > people > doctor
c ++ + ++ c = 6
问题
父类对象调用子类的函数 需要强制类型转换为子类对象
static关键字
package com.oop.demo01;
public class Student extends People{
{
System.out.println("none-name-code-module");
}
static {
System.out.println("static code module");
}
public Student() {
System.out.println("constructor modele");
}
public static void main(String[] args) {
Student student = new Student();
System.out.println("===========================");
Student student1 = new Student();
}
}
// static --> 匿名代码块 --> 构造函数 静态代码块只加载一次
// final 类不能被继承 static不能调用动态函数 动态函数可以调用静态函数