• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

polymorphism in java

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the code tag as am new to this
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are a way to format your code on your posts.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So with this code, what is the question?
 
Tobi Taiwo
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is the error
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so, what do i do
 
Paweł Baczyński
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic