• final


     1 /**
     2  * final修饰的变量 是常量 只能赋值一次 不能被改变
     3  * final 修饰的方法  不能被重写 但是可以重载
     4  * final修饰的类       不能有子类 ,不能被继承。比如 Math  String
     5  * @author Administrator
     6  *
     7  */
     8 public class testFinal {
     9     //  final修饰的变量 是常量  常量名用大写 和 下划线命名 是不可改变的
    10     final int MAX_VALUE= 200;
    11     //再次赋值是不行的 MAX_VALUE=300;
    12     
    13 }

    final修饰方法和类

     1 /**
     2  * 类前面加final 下面 子类Bird报错 说明 加了final不能被继承T he type Bird cannot subclass the final class Animal
     3  *方法加了final 就不能被重写 下面的重写方法报错  The method run() is undefined for the type Animal
     4  */
     5 //类前面加final 下面 子类Bird报错 说明 加了final不能被继承
     6 public /*final*/ class Animal {
     7     String eye;
     8     //方法加了final 就不能被重写 下面的重写方法报错
     9     //The method run() is undefined for the type Animal
    10     public void /*final*/ run(){
    11         System.out.println("跑跑!");
    12     }
    13 }
    14 
    15 class Bird extends Animal{
    16     
    17     public void run(){
    18         super.run();//调用的原来父类Animal的run();方法
    19         //不满意可以重写 overwrite
    20         System.out.println("飞啊飞");
    21     }
    22     
    23     public void eggsheng(){
    24         System.out.println("我是卵生");
    25     }    
    26 }
  • 相关阅读:
    mybatis cache标签的参数
    debian ab压力测试环境
    Linux/debian 服务器buff/cache占用过多 清除cache脚本
    IKAnalyzerUtil中文分词
    JVM调优
    debian9 rc.local开机启动文件不存在解决方案 并开机启动tomcat容器
    spring mvc-获取 @resposeBody
    SerializeUtil 序列化工具
    JS_4DOM
    Spring_5
  • 原文地址:https://www.cnblogs.com/PoeticalJustice/p/7617224.html
Copyright © 2020-2023  润新知