parent class constructor is called automatically when child class is instantiated in java -
this question has answer here:
abstract class { abstract void method(); } class b extends { b() { } void method() { } } class c extends b { c() { } }
when instantiate class c in main, automatically calls constructor b (parent class). normal or doing wrong?
there nothing wrong, there implicit call super
constructor.
you haven't written constructor class c
default constructor provided compiler be.
c(){ super(); }
if default constructor provided, there call super()
. in case, c extends b
constructor of b
gets called.
if not class other class, default extends object
class. object
class constructor called.
Comments
Post a Comment