Bonjour, j'ai un probleme concernant l'utilisation de mes classes derivee..
Voila mon probleme j'ai une classe abstraite Account et ses deux classes derivee que voici:
je range mes objets de type Account dans une hashtable. Dans une autre classe qui implemente une interface, j'ai une methode qui doit retourner le type BankAccountOutputVO, en allant chercher les objets ranges dans ma hashtable
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 abstract class Account { public String name; public int accountNumber; private double balance; public Account(int accountNumber, String name, double amount) { this.accountNumber = accountNumber; this.name = name; this.balance = amount; } } class CurrentAccount extends Account { private final String TYPE = "Current"; private double overdraft; public CurrentAccount (int accountNumber, String name, double amount, double overdraft) { super(accountNumber, name, amount); this.overdraft=overdraft; } } class SavingAccount extends Account { private String rateInterest; private final String TYPE = "Savings"; public SavingAccount (int accountNumber, String name, double amount, String rateInterest) { super(accountNumber, name, amount); this.rateInterest=rateInterest; } }
Mon probleme est que dans ma table, l'objet est soit un de type CurrentAccount, soit SavingAccount, tout deux derives de Account, et donc je n'ai pas acces ou champs overdraft et rateInterest puisqu'il sont derives.. comment faire?? j'espere avoir ete assez clair .. merci..
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 public final class BankAccountOutputVO { private final String accountNumber; private final String accountType; private final String name; private final String balance; private final String overdraft; private final boolean successfulTransaction; public BankAccountOutputVO(String accountNumber, String accountType, String name, String overdraft, String balance, boolean successfulTransaction) { this.accountNumber = accountNumber; this.accountType = accountType; this.name = name; this.overdraft = overdraft; this.balance = balance; this.successfulTransaction = successfulTransaction; }
Partager