Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java inheritance after compilation

Tags:

java

class Car extends Viecle

Caris compiled.

Class Client uses Car.

Are fields and methods from Viecle put into Car class during compilation, or Car simply needs class Viecle to be compiled (and not removed) in compile and after - during runtime?

like image 830
dantuch Avatar asked Feb 24 '26 14:02

dantuch


1 Answers

The latter, Car needs Vehicle to be compiled and included at runtime.

If this were not the case, there would be quite a lot of needless code duplication in class files, if Vehicle were inherited 10 times, the code would be included 11 times total in the system. This would both take both unnecessary memory and CPU time to JIT compile.

like image 180
Joachim Isaksson Avatar answered Feb 26 '26 03:02

Joachim Isaksson