Addition and subtraction of final byte and byte variables

    //说明:byte初始化必须为<a href="https://www.jb51.cc/tag/yige/" target="_blank" class="keywords">一个</a> 常量值
    byte b1=1,b2=2,b3,b6;
    final byte b4=4,b5=6;
    b6=b4+b5;// byte=常量+常量
    b3=(b1+b2);//byte=int,故非法


    byte a1=1,a2=3,a3,a4;
    final byte a5=5,a6=6,a7; //a5,a6,a7均是常量
    a3=(a1+a2);//1  byte=int,故非法
    a4=(a5+a1);//2  byte=int+常量=int,故非法
    a4=a5+a6;//3    byte=常量+常量
    a7=a5+a6;//4    常量=常量+常量

    Sy<a href="https://www.jb51.cc/tag/stem/" target="_blank" class="keywords">stem</a>.out.println(b3+b6);

}

}

To illustrate:

The variable modified by final is the basic form of defining a constant in Java.

Source of original question: niuke.com:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>