• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance of interface by subclass  RSS feed

 
Olga Matveeva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

question appeared while solving PoolPuzzle from Heads first Java on page 265.
I use Eclipce to write and run the code.

The code is that one below (all classes in respective tabs for Eclipce, below is just a copy from book).

Question is the highlighted string. The IDE says that there is an error, because abstract method from the interface (which is called Nose) must be implemeneted; technically, it IS implemented in the Picasso which is superclass for Clowns (Clowns extends Picasso). BUT for some reason implementation is not happening and the IDE returns that Clowns must implements abstract methods. Any ideas how that can be? Anything wrong there?









 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Your code was horribly difficult to read, so I added indentation and code tags. Always use the tags: doesn't it look better now You cannot use coloured text inside code tags.
The only error was that in Of76 line 11 you had written “ ” rather than " ". I have corrected that in your post and it runs all right on my machine. There was no error in your Clowns class, which you had highlighted. You must have made some tiny spelling error on Eclipse and not copied the code exactly as you had it. How did you get “ ”? Did you use a word processor (=WP)? Never use a WP for coding because they may introduce control characters and smart quotes which will upset the compiler.
 
Olga Matveeva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Welcome to the Ranch

Your code was horribly difficult to read, so I added indentation and code tags.


Thanks!
Sorry for that. Just joined and havent learned to use that option yet.


Campbell Ritchie wrote: Did you use a word processor (=WP)? Never use a WP for coding because they may introduce control characters and smart quotes which will upset the compiler.


No, I was just a bit lazy to copy a distributed pieces of code from their respective class tabs from Eclipse and placing respective curly brackets, so easier was to copy from book. But there is no spelling error in my version, I was not coping the code, I was writing it before checking with the solution and then corrected the mistakes. So the only mistake I am getting is the one mentioned - in Eclipse it says that "The type Clowns must implement the inherited abstarct method Nose.iMethos()".

UPD

Yes, this was the spelling mistake in 1 letter. Gosh you were right. Thanks a lot!

(So, this was the mistake in 1 letter in the method in Picasso, so instead of a method from interface being implemented, there was just a new method created, and thus the subclass was not in fact inheriting any implemented methods from its superclass.)
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done finding the error A one‑letter misTake like that can be very difficult to see. Even worse if it is a capitalisation problEm. Lots of people have difficulty with System.out.println because they write System.out.printIn.
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember in our study days, teachers insisted on copy/pasting as much as possible instead of writing the names to avoid this kind of mistakes.
 
Olga Matveeva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tapas Chand wrote:I remember in our study days, teachers insisted on copy/pasting as much as possible instead of writing the names to avoid this kind of mistakes.


Oh, come on it made me go through the logic of code again and through the chapter, making that course material to become an active part during that troubleshooting. If I was just to copy the code, that would be the same as reading it and forgetting soon after. Of course I would rather modify the example code to create smth new on top of it but it might be just a bit early for me. Most primitive mistakes are corrected by IDE itself, but in that case this was mistake not in spelling the command, but the variable title. Absolutely legal I would say, but changing the design.
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I did not explain properly.
By copy/paste I did not mean copying code from any other source.
I mean if a variable has been declared like String transactionDesciption;
Whenever I use transactionDesciption subsequently, I should copy it from the initial declaration statement, thus avoiding any spelling mistake.
Of course IDE can do it by CTRL+Space. But I was referring to the study days (we were not allowed to use any IDE, did learn core java using edit plus )
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what @Override is for.
 
Olga Matveeva
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tapas Chand wrote: But I was referring to the study days (we were not allowed to use any IDE, did learn core java using edit plus )


Ah, I see
I started this course as well only using the TextEdit and command line. It though required sometimes changing a bit the structure of the code, because the way exactly it was done in the book, it was not always processed by javac.

But then I changed to Eclipse, for me it seemed not to be anyhow harmful for the learning process. Are there any reasons actually to stay with plain text code writing?
 
Campbell Ritchie
Marshal
Posts: 56598
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you are familiar with the use of the command line and the options and can compile multiple classes in multiple packages from the command line, you probably have a program large enough to benefit from moving to an IDE.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Once you are familiar with the use of the command line and the options and can compile multiple classes in multiple packages from the command line, you probably have a program large enough to benefit from moving to an IDE.


...and you'll also probably understand what the IDE is doing for you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!