Google Answers Logo
View Question
 
Q: Java Inheritance Issues... ( No Answer,   2 Comments )
Question  
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!

Request for Question Clarification by aardvark-ga on 26 Feb 2003 18:48 PST
If you could make enough code available to where I can try to compile
it myself, I can definitely help you with this.

Clarification of Question by wahooka-ga on 26 Feb 2003 19:11 PST
Sure I will post the source code. But remember I am still kinda in the
middle of the code, espically since I got stuck with this part. There
are a few parts to the program. Also I should note this is a model of
an ATM machine.
The GUI Client interface includes:
Frame1.java
Application1.java
Client.java

The server includes:
Server.java
Bank.java
CustomerAccount.java

I am using Metrowerks Codewarrior for this project, but it should also
compile (or at least give errors ;) with javac. And also note, the
server must be running for the client to interface with it. You can
see sample PIN numbers are in Bank.java class.

Here is where you can download the source files:

http://www.hiddentreasurehosting.com/source/

If you have any future questions, please feel free to ask. Also if you
see any good modifications to my code and suggest them, or better yet,
make them, I will tip very generously.

Thanks for the help.

Request for Question Clarification by aardvark-ga on 26 Feb 2003 19:39 PST
I've successfully compiled the code, Unfortunately the server returns
a "Bus Error" when I run it on my Mac.  I'll give it a shot on Windows
when i get to work in the morning.

Clarification of Question by wahooka-ga on 26 Feb 2003 19:51 PST
I have uploaded new source files, so if anyone is looking at them
please get the latest at the same above site.

Thanks for your effort aardvark-ga and also for your thoughts,
secret901-ga. That certainly makes some sense what you said about
causing the infinite loop. If you can suggest a good way to attack
this problem, showing an example or even implementing it, I can
consider this question closed.

If any solution is worked out tonight I will have a nice tip added.
Thanks again!
Answer  
There is no answer at this time.

Comments  
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

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

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 Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy