Re: using super
- From: "Bjorn Abelli" <bjorn_abelli@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 9 Nov 2005 09:44:09 +0100
"fb" wrote...
> 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.
You're right about the use of 'super' in this case.
However, I'm curious of why you hide attributes from the superclass in the
subclass?
> abstract public class Transaction{
> //Data attributes
Somewhere here you must have defined 'Date transDate', as you're able to
assign it a value inside the constructor of Transaction.
Logically I would guess that you also have a 'double amount' in there
somewhere, as you certainly must have a method 'setAmount(double)'.
> //Constructor(s)
> Transaction(double amount, Date transDate){
> setAmount(amount);
> this.transDate = transDate;
> }
> }
>
> import java.util.Date;
> public class Credit extends Transaction{
> //Data attributes
These attributes never gets assigned, as you delegate the assignment to the
super constructor.
My guess is that you really don't want to use these attributes, but the
inherited ones instead.
> private double amount;
> private Date transDate;
>
> //Constructor(s)
> Credit(double amount, Date transDate){
> super(amount ,transDate);
> }
> }
// Bjorn A
.
- References:
- using super
- From: fb
- using super
- Prev by Date: Re: using super
- Next by Date: Re: Java Session in JSP
- Previous by thread: Re: using super
- Next by thread: Re: using super
- Index(es):
Relevant Pages
|