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

 

相关文章:

  • 2021-12-24
  • 2021-06-26
  • 2021-12-26
  • 2022-12-23
  • 2021-04-21
猜你喜欢
  • 2022-03-09
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2022-02-19
  • 2021-12-24
相关资源
相似解决方案