This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I didn’t want to ask this question until I received the instructor’s solution for OOP-1, so now that I have it, I have a couple of questions about OOP-2 (NaturalLanguageMultiply).
I was reading the story How My Dog Learned Polymorphism and I wanted to make sure of a couple of things. At the beginning of the story, the following is stated:
Dog extends Animal
Animal is a superclass of Dog
Dog is a subclass of Animal
Dog inherits from Animal
Dog overrides the play() method
Dog adds one new method, bark()
During the story, the question is asked of which “play” method is called in the following:I understand that it is the one from Dog and not animal. That seemed pretty straight forward to me.
Later the following question is asked again about which “play” method is being called:
If I understand correctly, at compile-time, the “play” method from Animal is used, but at run-time the “play” method from Dog is used.
Are each play methods different from each other, as in each does a different thing or are they the same thing just being used at different times?
I read the rest of the story, I then re-read it a few more times and there is something that is not clicking in my head. Is there something I’m missing or is that bloody dog smarter than me?
Look up static vs dynamic binding.
Good reading about that topic.
Joined: Feb 10, 2010
Thanks for the pointer Gary, I'll take a look at it.
Right now, I have a working script that does the correct conversions and calculations on the numbers I enter (ex. thirty-two ten or five six or any combination thereof). I did this without using inheritance (maybe I should have, but I don't think so, I'll leave that to the nitpickers to let me know). I'm about to start working on the throw/catch exception part of the script and was wondering if the inheritance part of the assignment is for the throw/catch exceptions only?
I think that you only need one class for this assignment. You don't need to worry about inheritance quite yet. The time for that is coming soon.
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Joined: Feb 10, 2010
Thanks for the heads up Marilyn. The only thing I'm inheriting right now is a headache. I have the script working at about 90%, it does all the math correctly, but I can't for the life of me get the throw / catch exception to work. I've tested it and the script runs the test, but if I enter incorrect information (ex. TEEN twenty-three, instead of ten twenty-three), I get the nullpointerexception error from java, instead of my error message.
Anyways, I'm off on vacation for a few days and will take a look at this when I get back, maybe time away will do me some good.
Happy Canada day to my fellow Canucks on this forum.