下列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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM