Can some one explain me the difference between implicit constructor and explicit constructor in Java?
-
1An implicit constructor is one that's not explicitly coded. – Hot Licks Jun 03 '14 at 11:07
1 Answers
Explicit means done by the programmer. Implicit means done by the JVM or the tool , not the Programmer.
For Example:
Java will provide us default constructor implicitly.Even if the programmer didn't write code for constructor, he can call default constructor.
Explicit is opposite to this , ie. programmer has to write .
Default constructor is the constructor with no arguments requested. It is called implicitly when creating an instance.
The no-args constructor is called implicitly if you don't call one yourself, which is invalid if that constructor doesn't exist. The reason it is required to call a super constructor is that the superclass usually has some state it expects to be in after being constructed, which may include private variables that can't be set in a sub-class. If you don't call the constructor, it would leave the object in a probably invalid state, which can cause all kinds of problems
- 33,936
- 20
- 234
- 300