final修饰变量——不可改变的量(常量)
final修饰方法——不可被重写
final修饰类——不可被继承
7.10代码:
public class Qiltj {
static final double PI = 3.1415926;
public static void main(String[] args) {
System.out.println("圆周率的值为:"+ PI);
System.out.println("半径为3的圆的周长为:"+ (2 * 3 * PI));
//尝试修改PI的值
PI = 3.1415927;
}
}
7.11代码:
class Qiltk {
public final void turnOnTheTV() {
System.out.println("爸爸打开了电视");
}
}
class Baby extends Qiltk{
public final void turnOnTheTV() {
System.out.println("宝宝也要打开电视")
}
}