final修饰特点
* 修饰类,类不能被继承
* 修饰变量,变量就变成了常量,只能被赋值一次
* 修饰方法,方法不能被重写

 

public  static  final  double PI=3.14;  final 一般跟static一起用!

==========================================

  final  class  person {   //final修饰类 不能被继承

String  name ;

int  age;

public person(){...}

}

-------------------------------------------

class person{

final  int NUM=10;

public void print(){

NUM=20;//无法通过编译

System.out.println(num);

}

}

---------------------------------------------

 

class  person{

public final void print(){

System.out.println("final");

}

class student extends person {

public void print(){

System.out.println("public ");//无法通过编译

   }

  }

}

  

相关文章:

  • 2021-04-10
  • 2021-07-15
  • 2021-11-27
  • 2021-06-12
猜你喜欢
  • 2021-08-22
  • 2022-01-21
  • 2021-10-02
  • 2022-02-28
  • 2021-10-16
  • 2021-12-03
  • 2021-12-01
相关资源
相似解决方案