Re: using super
- From: Noodles Jefferson <silverbells@xxxxxxxxxxxxxx>
- Date: Wed, 9 Nov 2005 01:09:16 -0600
In article <srfcf.449727$tl2.350382@pd7tw3no>, fb took the hamburger,
threw it on the grill, and I said "Oh wow"...
> Hello Everyone. I am trying to declare a constructor that accepts the
> same parameters as the Transaction constructor and pass them to the
> Transaction constructor.
>
> I think this should work, but I'm rather new to 'super' (and OOP in general)
>
> So, (in regards to the following code):
>
> If I'm right, when I use the 'super' keyword, I'm actually calling the
> constructor of the Transaction class and passing in the variables.
>
> If I'm wrong...well, I'm sure you'll let me know. :-)
>
> abstract public class Transaction{
> //Data attributes
> ...
> ...
> ...
>
> //Constructor(s)
> Transaction(double amount, Date transDate){
> setAmount(amount);
> this.transDate = transDate;
> }
> }
>
> import java.util.Date;
> public class Credit extends Transaction{
> //Data attributes
> private double amount;
> private Date transDate;
>
> //Constructor(s)
> Credit(double amount, Date transDate){
>
> super(amount ,transDate);
> }
> }
>
> So...do you think I got it?
>
Yep. Just like that.
Now if you do anything else in the constructor, make super the first
line. You have to call super first before you do anything else.
--
Noodles Jefferson
mhm31x9 Smeeter#29 WSD#30
sTaRShInE_mOOnBeAm aT HoTmAil dOt CoM
"Our earth is degenerate in these latter days, bribery and corruption
are common, children no longer obey their parents and the end of the
world is evidently approaching."
--Assyrian clay tablet 2800 B.C.
.
- References:
- using super
- From: fb
- using super
- Prev by Date: Re: using super
- Next by Date: Re: using super
- Previous by thread: Re: using super
- Next by thread: Re: using super
- Index(es):
Relevant Pages
|