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