JAVA变量初始化及变量作用范围
2013-03-20 13:33
351 查看
我将两个示例合并成了一个,来显示JAVA变量作过的范围,
我想在这真正运用的时候,可能才能获得更深入的了解吧。
运行结果:
我想在这真正运用的时候,可能才能获得更深入的了解吧。
public class TestVar { private int i = 100; private static String name = "Learn Java fastly!"; { int block = 10; } public int firstMethod() { int j = 1; System.out.println("in firstMethod, we can access static name :" + name); System.out.println("in firstMethod, i = " + i + ", j = " + j); return 1; } public int secondMethod(float f) { int j = 2; System.out.println("in secondMethod, we can also access static name :" + name); System.out.println("in secondMethod, i = " + i + ", j = " + j + ", f = " + f); return 2; } public static void main(String[] args) { TestVar t = new TestVar(); //System.out.println("in mainMethod, we can access var block :" + t.block); t.firstMethod(); t.secondMethod(3); } }
运行结果:
相关文章推荐
- Java变量的作用范围
- Java变量的作用范围
- 面试题:说说Java中接口、类、成员变量、成员方法、构造方法有哪些访问修饰符和他们的作用范围
- java变量的类别和作用范围
- 05_张孝祥_Java多线程_线程范围内共享变量的概念与作用
- 【Java多线程与并发库】5.线程范围内共享变量的概念与作用
- Java变量的声明、初始化和作用域
- 【Java多线程与并发库】5.线程范围内共享变量的概念与作用
- Java变量的声明、初始化和作用域
- 基于java变量和作用域以及成员变量的默认初始化(详解)
- java多线程之线程范围内共享变量的概念与作用
- 黑马程序员_java中变量作用范围
- Python变量的作用范围
- classpath、path、JAVA_HOME的作用及JAVA环境变量配置
- JAVA实例变量的初始化过程
- java中的修饰符作用范围
- java在方法里new一个对象的生命周期及作用范围
- Java中static变量作用和用法详解
- Java变量初始化
- java----对象初始化及变量的缺省值