简体   繁体   中英

JAVA memory use of extended class

The situation: I have parent class PARENT. Several classes which extends PATENT.

So question is: in memory is created as much copies of PARENT as there is CHILDS. Or in memory there is only one copy which is used by all CHILDS?

每个CHILD方法,每个PARENT方法等只有一个副本。每个CHILD对象都有其类的每个非静态字段,每个PARENT的非静态字段以及每个Object的非静态字段的副本。静态字段。

Instance of a class consists of its parents fields and its own fields.

class A {
   int a;
}

class B extends A {
    int b;
}

instance of B is one instance (no A instance is created) which has 2 fields: int a and int b

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM