![]() |
|
![]() | ||
|
Subject:
Java Inheritance Issues...
Category: Computers > Programming Asked by: wahooka-ga List Price: $5.00 |
Posted:
26 Feb 2003 16:25 PST
Expires: 26 Feb 2003 20:04 PST Question ID: 167587 |
I am having major difficulties with inheritance. I have a Java program thats a Server with two other classes, Bank and Customer account. Here is the begining part of the class declarations of each: public class Server extends JFrame { private JTextField enterField; private JTextArea displayArea; private ObjectOutputStream output; private ObjectInputStream input; private ServerSocket server; private Socket connection; private int counter = 1; CustomerAccount customer_account = new CustomerAccount(); // set up GUI public Server() { BLAH BLAH } ---------------------- public class Bank extends Server { public int pin; //each account has a pin public int ID; //each pin has an account ID associated with it CustomerAccount customer_account = new CustomerAccount(); public Bank() { } -------------------------- public class CustomerAccount extends Bank { public boolean checking_acct; public boolean savings_acct; public boolean moneymarket_acct; public boolean cd_acct; public int checking_bal; public int savings_bal; public int moneymarket_bal; public int cd_bal; public CustomerAccount() { } Now what I need is to create one instance of the object CustomerAccount in the Server class and it needs to inherit everything from the Bank class. I have been playing with this for literally hours and I can't get it. What do I need to change to get this working? My error when I try to compile is a HUGE LIST which seems repeating saying at "CustomerAccount.<init><CustomerAccount.java:28>at Server.<init><Server.java:20>at Bank.<init><Bank.java:21>" Also a little more information is, in the CustomerAccount object which I need help creating, I need to access the methods in the CustomerAccount class as well as the Bank class. How would I properly identify the methods from each class? For example, if Authenticate is a method in the bank class, would it be: customer_account.Authenticate(int whatever); or am i wrong here too? If you need more of my code or have any questions, please just ask. And I need the help as soon as possible so answer in a speedy manner and correctly and you'll get a little bonus! Thanks for the help! | |
| |
| |
| |
|
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: Java Inheritance Issues...
From: secret901-ga on 26 Feb 2003 19:36 PST |
Hi wahooka, It appears to me that the classes Bank, CustomerAccount, and Server are not related to each other and should be best dealt with without inheritance. The problem with letting CustomerAccount inherit Bank which inherits Server is that every time you create a CustomerAccount, a Bank, and in effect, a Server is created. However, since both Server and Bank contain CustomerAccounts in them, new CustomerAccounts must be created. This process thus continues ad infinitum, creating the problem that you see. |
Subject:
Re: Java Inheritance Issues...
From: secret901-ga on 26 Feb 2003 19:43 PST |
(continued) Thus, your problem boils down to one similar to the following: public class Parent { Child child = new Child(); public static void main(String[] args) { Parent parent = new Parent(); } } class Child extends Parent { } To avoid the problem, make sure that the parent do not contain any instance of child, or don't link them through inheritance at all. secret901-ga |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |