用final修饰 最后
变量 方法
㈠ 变量 不可被修改
㈡ 方法不可被重写
重写方法的判断依据
①同名 ② 同参 ③ 范围不小于 ④ 返回不大于 ⑤ 异常不多于
㈢ finail 所修饰的类,不可被继承 太监类
重写 重载: 多态的体现
① 重写出现在父子类中
重载在同一个类中
② 重载的参 一定不同
重写的参 一定相同
③ 重载 overload
重写 override
④ overload 不限定返回值的范围异常,
override 严格规定范围返回值异常
This 和 super (主讲用法)
㈠ 作为非静态方法的隐含参数,作为对象使用
作为对象使用: 每一个本类的/*this.super*/ 只有对象能调用方法和属性。
this是调用方法的对象
super 是调用方法的对象的父类对象。
静态方法中 没有This super
㈡ 作为构造方法使用,用来调用个重载构造方法
内部类
1 成员内部类 类中 (staticX)
2 局部内部类 语句块 方法体
3 静态内部类 static (staic)
4 匿名内部类
修饰词 public修饰
package Day05;
public class Demo04 {
public static void main(String[] args) {
Sub04 s = new Sub04();
}
}
class Super04{
Super04(){
System.out.println("父类无参");
}
Super04(int x)
{
System.out.println("父类: int= "+x);
}
Super04(String str)
{
System.out.println("父类: Str= "+str);
}
Super04(String str,int x)
{
System.out.println("父类: Str="+str+" x = " + x);
}
}
class Sub04 extends Super04{
Sub04(){
this("s"); //找自己
System.out.println("子类无参");
}
Sub04(int x)
{
System.out.println("子类: int= "+x);
}
Sub04(String str)
{
super("hehe",8); //找父类
System.out.println("子类: Str= "+str);
}
Sub04(String str,int x)
{
System.out.println("子类: Str="+str+" x = " + x);
}
}