Hello, I need to fix my baisics, pl hlp me. Ihave two classes as given below. and not able to compile class B, though I am assuming that when a class extends other it also gets all the constructor of its parent class. Am I wrong? If so than why it compiles and call the parent class default constructor, if I write B x = new B() instead? pl help me to understand this. regards, Arun
[ September 18, 2002: Message edited by: arun mahajan ]
Thanks for your replies. Yes I am not defining the B(String s) assuming that it will call the parent constructor and Thomas if constructors are not inherited than why it calls the parent default constructor. What I mean if I say B x = new B() it output the print value of class A's default constructor. What's the OOPs concept here? Is it say that it will only go for the default one nothing more regards, Arun
The first thing every constructor must do is either invoke another constructor of the same class or invoke a super constructor. An instance of the superclass must be created before an instance of the subclass is created. (Nevermind about what the first thing that a constructor of Object does). If the programmer does not include an explicit invocation of a super constructor, then the compiler adds that line of code for you (so to speak). The constructor that the compiler chooses by default is the default (no arguments) constructor. Does that clear things up a bit? [ September 19, 2002: Message edited by: Dirk Schreckmann ]
Thanks Thomas for your reply. What I could understand now from yours and Dirk answer is that constrcutors can not be inherited( as you said earlier). As a matter of fact I tried modifying the code in following manners and answers were surprising to me but perhaps it make this sense only: 1. If I want to call any parameterised constructor of a super class I should use super method for that. 2.Otherwise it calls the default only. Am I right? regards, Arun