zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    EF Power Tools
    ntsysv命令
    chpasswd 批量更新用户口令
    at定时执行任务命令详解
    shell
    为什么使用 shell 编程
    shell
    redis cluster 3.0
    CSS命名规则规范整理
    log4j:WARN No appenders could be found for logger
  • 原文地址:https://www.cnblogs.com/PoeticalJustice/p/7617224.html
Copyright © 2011-2022 走看看