⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localvariabletest.java

📁 《Java核心技术应用开发》电子工业出版社书籍源代码
💻 JAVA
字号:
/**
 * 这个类有编译错误
 * 演示了局部变量的使用
 */

package sample;

public class LocalVariableTest {
    // int x;        
    public void correctLocalV() {
        int x;  //Just declare
        int y = 10; //Declare and initiate
        x = 20; //Evaluate
        int z = x + y; //Declare and initiate
        String str = "Hello"; //Declare and initiate
        String str1 = new String("World"); //Declare and initiate
        char ch; //Just declare
        ch = 'c';  //Evaluate
    }
    
    public void incorrectLocalV() {
        int x, z;  //Declare only
        int y = 10;
        if( y > 20) z = x + y; //x isn't be initiated
        String str; //Declare only
        String str1 = "Hello" + new String(" World") + str; //str isn't be initiated
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -