Forums Register Login

polymorphism in java

+Pie Number of slices to send: Send
please help with this i access methods of class A in class B and then i access class variable of class B in Class A but its giving a runtime error. note that both were done using java polymorphism attribute
+Pie Number of slices to send: Send
Welcome to the Ranch.

Could you post some working code? And when you do, remember to use code tags.
+Pie Number of slices to send: Send
what is the code tag as am new to this
+Pie Number of slices to send: Send
They are a way to format your code on your posts.
+Pie Number of slices to send: Send
Welcome to the Ranch. The following page explains code tags: Use Code Tags. You should use them so that the forum can display your source code nicely formatted.

And Knute is right, your question is really hard to answer without seeing your source code. What do you mean with "Java polymorphism attribute"?
+Pie Number of slices to send: Send
okay, this is just an example,

when i run this it gives me an error but doesn't show an error before, i mean it shows a runtime error saying hashmap or something and also i could have put the acc inside the solve method but i choose this way as dis is an example
+Pie Number of slices to send: Send
That's not working code. Get rid of the errors and post the code in another message (don't edit the original).

Remember that Java is cAsE sEnSiTiVe.
+Pie Number of slices to send: Send
 

Tobi Taiwo wrote:it shows a runtime error saying hashmap or something


Don't paraphrase. Copy and paste the exact error message - they usually provide a lot of useful information for debugging problems.
+Pie Number of slices to send: Send
sorry i just use that as an example not caring about the case sensitivity
this is the second


this is the second

this is the rest

as i said its unfinish
this are the rest

and also

lastly
+Pie Number of slices to send: Send
remember its not finish and the problem is with withrawal and bankdatabase when i run it, it gives error
+Pie Number of slices to send: Send
So with this code, what is the question?
+Pie Number of slices to send: Send
i'm getting error when i run it, i think the problem have to do with Bankdatabase calling withrawal and then again withdrawal call Bankdatabase.
how do i solve this as both depend on each other
+Pie Number of slices to send: Send
And what is the error you're getting? Remember, specific and post any stack traces or error messages.
+Pie Number of slices to send: Send
this is the error
+Pie Number of slices to send: Send
Your BankDatabase is creating a new instance of Withdrawal which is creating a new instance of BankDatabase which is creating a new instance of Withdrawal which is creating a new instance of BankDatabase which is creating a new instance of Withdrawal which is creating a new instance of BankDatabase which is creating a new instance of Withdrawal which is creating a new instance of BankDatabase which is creating a new instance of Withdrawal which is creating a new instance of BankDatabase which is creating a new instance of Withdrawal which is creating a new instance of BankDatabase which is....
And so on and so on until the stack explodes.
+Pie Number of slices to send: Send
so, what do i do
+Pie Number of slices to send: Send
You need to rethink your design.
I doubt bank database needs an instance of withrawal as a member.
I also doubt a withdrawal needs an instance of bank database. Or keypad. Or screen.
+Pie Number of slices to send: Send
Quickly glancing at the last set of code snippets that you've posted explains all of your problems... You have a system that was not properly designed

Its architecture is tightly coupled and the components are of low cohesion... I suggest you scrap the whole thing and start from scratch instead of trying to fix it...

One thing that is quick to notice is the fall through statements in the switch construct...

Next you are creating objects that merely perform a desired action, therefore they don't qualify to be instantiated... They contain no state attributes... These can be transformed into utility components by making there methods static


Now it can be used like -> int menuInput = Keypad.getInput();

Overall, redesign your system without thinking about programming syntax and focus on the interaction between the components of the system... Make each component perform one specific task and you should end up with better results...
+Pie Number of slices to send: Send
thanks
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 952 times.
Similar Threads
run-time and compile-time
Dynamic polymorphism and Overriding
Is it Polymorphism Concept wrong or right?
Are static members inherited?
compile-time polymorphism
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:07:35.