下列java代码中的变量a、b、c分别在内存的______存储区存放。
1 class A{ 2 private String a = "aa"; 3 public boolean methodB(){ 4 String b = "sb"; 5 final String c ="adsf"; 6 } 7 }
-------------------------------------------------
正确答案是 a在堆中存放 bc在栈内存放。
why?
a属于类所以在堆中。bc属于方法,b c为局部变量,局部变量不属于任何类或者实例,因此它总是保存在其所在方法的栈内存中!
bingo!!!!!!!
----------------------------------
第二题 输出结果是什么?
--------------------------------
public class HelloB extends HelloA { public HelloB() { } { System.out.println("I’m B class"); } static { System.out.println("static B"); } public static void main(String[] args) { new HelloB(); }}class HelloA{ public HelloA() { } { System.out.println("I’m A class"); } static { System.out.println("static A"); }}有兴趣 加群 一起交流 581688467
拼了命、尽了兴

浙公网安备 33010602011771号