• Post Reply Bookmark Topic Watch Topic
  • New Topic

polymorphism in java  RSS feed

 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Could you post some working code? And when you do, remember to use code tags.
 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the code tag as am new to this
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
They are a way to format your code on your posts.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"?
 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
remember its not finish and the problem is with withrawal and bankdatabase when i run it, it gives error
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So with this code, what is the question?
 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Knute Snortum
Sheriff
Posts: 4287
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And what is the error you're getting? Remember, specific and post any stack traces or error messages.
 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the error
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so, what do i do
 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!