Hi, So please let me know that if I dont use super or this ,then what would be more suitable way to write the above asked code. [ August 18, 2008: Message edited by: Ulf Dittmer ]
Joined: Aug 05, 2005
Originally posted by eshu khare: So please let me know that if I dont use super or this ,then what would be more suitable way to write the above asked code.
Depends what you are trying to do. Are you trying to call another constructor - if so use this as described in previous posts. If you just want to call a method, then your code will work. Rob was just saying that it would be better not to use the class name as the method name as it makes the code less readable. People might mistake the method for a constructor if they just glance quickly at the code.
Joined: Oct 13, 2005
If your class extends another class without a ******** constructor with no arguments, you must use super(something) somewhere. In that case any constructors which don't call super(something) as their first line must call this(something) so as to get to super(something) via the other constructors.
You call this(something) to pass parameters from one overloaded constructor to another in the same class. There is a Clock class which appears in P Deitel and H M Deitel Java How to Program. I am writing something similar to that class to demonstrate this()Without using this() to access the overloaded constructor it would read like this
Delete the word "declared" where the ******** now is.[/edit] [ August 18, 2008: Message edited by: Campbell Ritchie ]
Joined: Aug 01, 2008
Hi Guys, Thanks,though it was not my doubt even then got many things to learn;this is what Big Moose Saloon is.