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

1,035 阅读1分钟

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

题目很简单,如下

第一个类

    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个直接对象各需要多大的内存?