posted 11 years ago
When MySuper obj= new MySub(); executing,
1. it calls MySub's default constructor, then
2. MySub's default constructor calls MySuper's Constructor. now,
3. here you are calling disp() , actually this method call is happening on *this* reference of MySub.
4. now it calls MySub's disp method. right now still JVM not assigned value for i in MySub. because still super class constructor is running.
5. hence, the result.
Conclusion: dont call non-private and non-final methods in constructor. if the class can be sub classed.