成员变量

1.实例参数(不以static修饰)
2.类变量(以static修饰)

局部变量

1.形参
2.方法局部变量
3.代码块局部变量

package ch5;

/**
 * Created by Jiqing on 2016/11/12.
 */
public class VariableOverride {
    // 定义一个name实例变量
    private String name = "纪庆";

    // 定义一个类变量
    private static double price = 80;

    public static void main(String[] args) {
        // 方法中的局部变量
        int price = 65;
        System.out.println(price); // 65
        System.out.println(VariableOverride.price); // 80

        new VariableOverride().info(100);

    }

    public void info(int price) { // 形式参数

        {
            String name = "李四"; // 代码块变量
        }
        System.out.println(name); // 纪庆

        // 方法中的局部变量
        String name = "孙悟空";
        System.out.println(name); // 孙悟空
        System.out.println(this.name); // 纪庆
        System.out.println(price); // 100
    }

}

类变量与实例变量的内存机制
类变量、实参、形参、方法参数、代码块参数
类变量、实参、形参、方法参数、代码块参数
类变量、实参、形参、方法参数、代码块参数

类变量、实参、形参、方法参数、代码块参数



本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/6057846.html,如需转载请自行联系原作者

相关文章:

  • 2022-12-23
  • 2022-02-07
  • 2021-08-18
  • 2021-09-09
  • 2021-07-17
  • 2021-06-05
  • 2021-10-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案