You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
573 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

public class Jb26_Final
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
//继承的弊端:打破了封装性,会覆盖父类方法
/*
final关键字可以修饰类、方法和变量
修饰的类不能被继承继承
修饰的方法不可以被覆盖
修饰的变量是个常量,只能被赋值一次
内部类只能访问被final修饰的局部变量
常量所有字母都要大写多个单词用_连接
*/
class Fu
{
void method()
{
//调用底层系统资源
}
}
class Zi extends Fu
{
void method()
{
// final int x = 1;
// x = 2; 此会提示出错变量x为最终变量无法赋值
System.out.println("OK");
}
}