Why an empty class also internally contains default constructor after compiling? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

Why an empty class also internally contains default constructor after compiling?

Without creating any new instance or object what's the use of that constructor, that the compiler generates automatically and why?

8th May 2017, 5:38 PM
Pintu
Pintu - avatar
3 Antworten
+ 11
The default constructor implicitly calls the superclass's nullary constructor, then executes an empty body. All fields are left at their initial value of 0 (integer types), 0.0 (floating-point types), false (boolean type), or null (reference types). Source: https://en.m.wikipedia.org/wiki/Default_constructor
8th May 2017, 7:32 PM
Tashi N
Tashi N - avatar
0
But m talking about only a simple class having no super class also creates a constructor implicitly. why?
9th May 2017, 9:00 AM
Pintu
Pintu - avatar
0
From my study i got that an empty class also contains a constructor because object of this class can be created in other class and compiler doesn't know when and which class will create obeject of this class. [Generally .class file depends on its .java file]
10th May 2017, 8:24 PM
Pintu
Pintu - avatar