复盘:
final关键字正如其名字一样,最终的,可以修饰变量(属性和局部变量),方法,代码块、类。
对于final修饰的类,表示该类不可以再被其他类继承,已经到了最后一代。
final修饰方法:表示方法不可以被重写
final修饰变量:表示是一个常量,通常定义全局变量时与static连用,static final
笔记:
package oop.keywords;
public class FinalTest {
final int WIDTH=10;//显式初始化
final int LEFT;
final int RIGHT;
final int DOWN;
{
LEFT=1;
}
public FinalTest()
{
RIGHT=2;
this.DOWN = 0;
}
public FinalTest(int n)
{
RIGHT=n;
this.DOWN = 0;
}
public void doWidth()
{
// width=11;The final field FinalTest.width cannot be assigned
}
public void show()
{
final int NUM=10;//final修饰方法体里面的局部变量
}
public void show(final int num)
{
// num=20;
}
}
final class Final{
}
//class B extends Final{
//
//} the type B cannot subclass the final class Final
//class A extends String{
//
//}
class AA{
public final void show()
{
}
}
class BB extends AA
{
// private void show() {
// // TODO Auto-generated method stub
//
// } Multiple markers at this line
// - Cannot override the final method from AA
}



