Kaplan self test OCAJP7 practice set => Item: 5 (Ref:1Z0-803.6.5.6)
Rakesh kumar Gupta wrote:Which statement is true about constructor overloading?
if you add an explicit constructor, no default constructor will be provided by the compiler and therefore only one constructor
exists and there is no overloading taking place
Kaplan Self test practice explain it as...
Rakesh kumar Gupta wrote:2. A default constructor can be overloaded in a subclass.
Kaplan Self test practice explain it as...
Explanation:
A default constructor can be overloaded in a subclass. If no constructor is defined for a
class, then the compiler will automatically provide the default constructor. Because a
subclass can define its own constructors without affecting the superclass, a constructor with
parameters can be defined that invokes the superclass constructor, implicitly or explicitly.
[...]
The constructor must not use a different name. In the same class, an overloaded constructor
uses the same name. Because subclasses differ in name from their superclass, an
overloaded constructor will have a different name.
Kaplan Self test practice explanation wrote:A default constructor cannot be overloaded in the same class. This is because once a
constructor is defined in a class, the compiler will not create the default constructor. Thus, an
attempt to overload the default constructor will effectively remove it from the class.
Kaplan Self test practice explanation wrote:The constructor does not need to use the this keyword. The this keyword allows a constructor to
reference other constructor methods and/or instance context. Using the this keyword is not required in an
overloaded constructor.
Kaplan Self test practice explanation wrote:A default constructor can be overloaded in a subclass. If no constructor is defined for a
class, then the compiler will automatically provide the default constructor. Because a
subclass can define its own constructors without affecting the superclass, a constructor with
parameters can be defined that invokes the superclass constructor, implicitly or explicitly.
Kaplan Self test practice explanation wrote:The constructor must not use a different name. In the same class, an overloaded constructor
uses the same name. Because subclasses differ in name from their superclass, an
overloaded constructor will have a different name.
Rakesh kumar Gupta wrote:I understand when constructor overloading takes place.
But inKaplan Self test practice explain it as...
Don't get me started about those stupid light bulbs. |