A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 繁华落幕 中级黑马   /  2015-6-17 21:30  /  450 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

给定java代码,如下:  
public class Test{
static int i;
public int aMethod( ){
i++;
return i;
}
public static void main(String [] args){
Test test = new Test( );
test.aMethod( );
System.out.println(test.aMethod( ));
}
}编译运行后,输出结果是( )。
想知道被static修饰的变量,是在内存中什么位置?

4 个回复

倒序浏览
你给i赋一个初始值试试
回复 使用道具 举报
我没记错的话,是在方法区里面
回复 使用道具 举报
静态常量会放在静态区
回复 使用道具 举报
iFmmer 发表于 2015-6-17 21:36
你给i赋一个初始值试试

不用赋值的..
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马