I`m reading the book, but currently stumbled upon a problem. I always write problems on paper first and then put it to test in the computer, but when i finished and checked the answer it was other than my answers.
The first set should print :B's m1, A's m2 , A's m3 (this is correct)
The second set should print: B`s m1, A's m2 , C`s m3, 13 (correct again)
The third set should print: A`s m1, A`s m2, C`s m3, 13(correct)
The last set should print: B`s m1, A's m2 , C`s m3, 13 , but the book says it should print: B`s m1, C`s m2, A`s m3
Is it my fault, or is the result in the book wrong?
Thanks in advance.
Most of the technical books and mainly those that are translated to another language carry lots of translation bugs, if it's your case then i recommend you to download/buy the english version of it and look at the same place, i had lot of problems with some books and it was because the translation was wrong.
About the Inheritance and Polymorphism there are some tips that i can give you to understand it easier, You must think that the type (variable) is your interface, even if a car have a BMW engine if it doesn't have an interface to access all features of BMW engine it will not be used, and even you driving a car that isn't a BMW it will use all BMW engine(the acceleration is made in a subaru but the behavior is like a BMW) features available on the interface. And it occurs naturaly if you pay attention to the Inheritance tree and the type of the variable, a "top-level" object can have it's own implementations of any method that is already implemented in it's super classes (aka overriding) but it will just call that method if the object is really of his own type, otherwise it will call the version of the real object respecting the interface contract (modifiers included).
Feel free to ask me anything!
www.BlackBeltFactory.com/ui#!/ref=jmotta, SCJP 6, OCWCD JEE5, OCE EJB JEE6
Thank you for your fast answers. My book is actually translated, but i checked both the original book and both have the same problem. The page is 192(in the 2nd edition), i just finished checking the errata and it isn`t posted there, i`ll see how i can post this error so others don`t get confused.
Thank you once more!
I have copied the following classes from the book with slight changes, and, like you, written a Mixed2 class which incorporates all the options. The line before the options tells you what to expect.The output is
campbell@queeg:~/java/page192$ java Mixed2
Top block: expect B A A
B's m1, A's m2, A's m3,
2nd block: expect B A C 13
B's m1, A's m2, C's m3, 13
3rd block: expect A A C 13
A's m1, A's m2, C's m3, 13
4th block: expect B A C 13
B's m1, A's m2, C's m3, 13
The error is not on page 192, but on page 195. There is a position error in the oblique lines. The upper pair of oblique lines show the } and the line correctly positioned on the left. The third oblique line, however, has its } about 5/16inch or 8mm below the code it refers to. Its right end is about 5/16inch or 8mm below the correct answer (A's m1, A's m2, C's m3, 13). The 4th line lacks a } and is also 5/16inch or 8mm below the code it refers to on the left. If you draw a new line parallel to that, but 5/16inch or 8mm higher, it will point to the last block of three lines on the left and to B's m1, A's m2, C's m3, 13 on the right. The correct answer was specified, but the line pointing to that answer has been printed out of register with the rest of the page. That is the erratum you ought to be reporting.
Thank you. It is an error between submitting the diagram with the correct answer and its being printed. I believe that diagram (page 195) was submitted showing the correct answers and has been printed incorrectly.