1. polymorphism
- 在runtime 判断引用对象的实际类型来调用其相应的方法。
- polymorphism出现的三个条件:inherit, override, superclass object refers to subclass object.
2.abstract
- 用abstract修饰的classs叫做抽象类,用abstract修饰的方法叫做抽象方法。
- 含有抽象方法的class必须为抽象类。
- 抽象类被继承时,抽象方法必须被重写。
- 抽象类不能被实例化。
- 抽象方法只能被声明,不需要实现。
- abstract class can not be instantiated, but its subclass can be cast to it. eg: abstract class Animal{} class Dog extends Animal{} Dog d = new Dog(); Animal a = (Animal) d.
3.final
- final定义的变量值不能被改变
- final可以用来define 形式参数(parameter)eg: public void like(final int b){} . it means the value of b can‘t be changed in method like.
- final定义的方法不能被重写
- final定义的类不能被继承 : public final class String, public final class Math, public final class boolean.
4.interface
- every interface can be implemented by several classes
- every class can implement more than one interface, but can only extend one superclass. implements more interfaces, use "," to separate each interface.
- interface is kind of special abstract class.
- methods in interface should be "public"
- variables in interface should be "public static final"
- interface can extend interface
5. upcasting downcasting