zoukankan      html  css  js  c++  java
  • 下列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

    拼了命、尽了兴
  • 相关阅读:
    腾讯精品课程
    什么都没有,先空出来!
    Python3-super().__init()__
    Python3-模块
    Python3-单例模式
    Python3-私有化修改
    Python3-私有属性
    Python3-面向对象-魔术方法
    Python3-面向对象-四种方法
    Python3-迭代器
  • 原文地址:https://www.cnblogs.com/zj-phper/p/6553306.html
Copyright © 2011-2022 走看看