public class educoder06{
final
标记的类不能被继承;
final
标记的方法不能被子类复写;
final
标记的变量(成员变量或局部变量)即为常量,只能赋值一次
public class educoder06{
public static void main(String args[]){
Bike1 obj = new Bike1();
obj.run();
Honda honda = new Honda();
honda.run();
Yamaha yamaha = new Yamaha();
yamaha.run();
}
}
class Bike1 {
int speedlimit = 90;
void run() {
speedlimit = 120;
System.out.println("speedlimit=120");
}
}
class Bike2 {
void run() {
System.out.println("running");
}
}
class Honda extends Bike2 {
void run() {
System.out.println("running safely with 100kmph");
}
}
class Bike3 {
}
class Yamaha extends Bike3 {
void run() {
System.out.println("running safely with 100kmph");
}
}
测试结果:
speedlimit=120
running safely with 100kmph
running safely with 100kmph