0
点赞
收藏
分享

微信扫一扫

java成员变量和非成员变量的区别

北邮郭大宝 2022-04-23 阅读 113
java

成员变量  在类中的方法外  在堆中   随着类存在   有默认的初始化值,可以直接使用
局部变量  在类中的方法内     在栈中  随着方法的调用存在     没有默认的初始化值,必须先赋值才可以使用

public class test{
     public int chengyuan;
    public void method(){
        int jubu;
        chengyuan=100;
        System.out.println(chengyuan);
    }
    public static void main(String[] args) {
       test test01=new test();
       test01.method();
       System.out.println(test01.chengyuan);
    }
}
举报

相关推荐

0 条评论