final声明的类不能被继承,即没有子类。String类就是final修饰的。
修饰方法时,方法可以被重载,但不能被重写。
class Foo {
final void test(int b) {
System.out.println(b) ;
}
//final修饰的方法重载
final void test(int a, int b) {
System.out.println(a+b) ;
}
}
class Goo extends Foo{
//final方法不能被重写
//final void test(int b) {
// System.out.println(b) ;
//}
}