一道比较少见的基础面试题,考考大家

我自己在之前面试蚂蚁的过程中,有遇到一个基础面试题,印象挺深的,比较少见,拿出来和大家分享下

题目很简单,如下

第一个类

    public class Person1  {
        
    }
复制代码

第二个类

    public class Person2  {
        int a;
    }
复制代码

第三个类

    public class Person3  {
        int[] a;
    }
复制代码

第四个类

    public class Person4  {
        int[] a = new int[2];
    }
复制代码

第五个类

    public class Person5  {
        int a;
        byte b;
    }
复制代码

现在,

    public static void main(String[] args) {
        Person1 p1 = new Person1();
        Person2 p2 = new Person2();
        Person3 p3 = new Person3();
        Person4 p4 = new Person4();
        Person5 p5 = new Person5();
    }
复制代码

那么,请大家告诉我从p1到p5,这5个直接对象各需要多大的内存?

分类:
后端
标签: