 
		粯子粥
2015-02-05 22:49
同一变量是否只可声明一次?
 
				class  AB
{
    public static void main(String[] args) 
    {
        //如果在同一个作用域就只能一次,如果不同作用域可以再次声明;如两个if判断语句中的c变量                int a = 5;
        int b = 6;
        System.out.println(a+b);
        if (a>2)
        {
            //int a;
            //这里如果你把上面的a的注释解开掉的话就会报错,因为a变量是整个类的全局变量
             String c = "the same";
            System.out.println(c);
        }
        
        if (b>2)
        {
            String c = "the same";
            System.out.println(c);
        }
        
    }
} 
				class  AB
{
    public static void main(String[] args) 
    {
        //如果在同一个作用域就只能一次,如果不同作用域可以再次声明;如两个if判断语句中的c变量                int a = 5;
        int b = 6;
        System.out.println(a+b);
        if (a>2)
        {
            //int a;
//这里如果你把上面的a的注释解开掉的话就会报错,因为a变量是整个类的全局变量
            String c = "the same";
            System.out.println(c);
        }
        
        if (b>2)
        {
            String c = "the same";
            System.out.println(c);
        }
        
    }
}
 
				还在同一作用域,,
Java入门第一季(IDEA工具)
1168092 学习 · 18754 问题
相似问题