@override 引用符号
如在基类里有一方法为 void f(int i),你想在继承类中override这个方法,在打字时不小心把方法定义写成了void f(float i),这时,编译器会认为你要overload方法f(),而不是overrid。为避免此类错误,可以在继承类中把需要override的方法标记为@override,当出现上述错误时,编译器会给出警告。
Composition or Inheritance
当不确定使用Composition or Inheritance时,就问一句“Do I need to upcast?”
The final Keyword
- using with data: The data can't be changed.The value of final variable can be set either at compile time or runtime.You can define a final variable without setting a value,but u have to set value in the constructor.
- using with methods: means the method can't be overridden.
- using with classes: means the class can't be inherited.