Re: using super




"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


.



Relevant Pages

  • Re: using super
    ... I am trying to declare a constructor that accepts the ... > same parameters as the Transaction constructor and pass them to the ... > I think this should work, but I'm rather new to 'super' ... > Transaction(double amount, Date transDate){ ...
    (comp.lang.java.help)
  • Re: overloaded constructors
    ... I have 1 constructor that does not take any parameters and now i want to ... // get the connection string from the application settings ... public ADODatabaseWrapper(SqlTransaction transaction) ...
    (microsoft.public.dotnet.languages.csharp)
  • SqlDataAdapter and optional transactions
    ... I recently switched from using MySQL to SQL server. ... connection the SqlDataAdapter will default to that pending transaction ... SqlDataAdapter constructor can't take a null transaction and assume ...
    (microsoft.public.sqlserver.programming)
  • using super
    ... I am trying to declare a constructor that accepts the same parameters as the Transaction constructor and pass them to the Transaction constructor. ... Date transDate){setAmount; this.transDate = transDate;}} ... public class Credit extends Transaction{//Data attributes private double amount; ...
    (comp.lang.java.help)
  • overloaded constructors
    ... database wrapper that i created to encapsulate the ado functionality. ... have 1 constructor that does not take any parameters and now i want to ... // get the connection string from the application settings ... public ADODatabaseWrapper(SqlTransaction transaction) ...
    (microsoft.public.dotnet.languages.csharp)