• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Error in method signature

 
Ranch Hand
Posts: 82
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
I just beginning learn object oriented programming and I've developed this class and works well, but the last method flag this suggestion "Add@Override Annotation"
can anyone tell me why???
further, I'd be grateful if you give me any advices about this class
Thanks in advance
 
Ranch Hand
Posts: 33
Mac Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

I'm just learning java too.. as far as I know this is because your method has the signature toString which means you are overriding the toString method of the object class which is the implicit superclass of all other classes. So this is just a suggestion for you to add the annontation to you code to say your are overriding a method of the superclass.

Hope this helps...
 
Sheriff
Posts: 22701
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Annotations. This one isn't required, but it's a good practice to always use the @Override annotation. That prevents you from making typos:
Since the method name is hashCode, with capital C, this is not overriding so there will be a compiler error.
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A general remark about your code:

The fan speed is set by an integer and you have defined 3 constants for the speed settings. However it's perfectly legal to call it with: fan.setSpeed(5000); (if 3 is fast then how fast would 5000 be ). A better way would be to define an enum.
 
Marshal
Posts: 76862
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And it might be a good idea to make the final fields public. Then other classes can invoke them to set the fan's speed.

As an atlernative, you can set bounds and refuse to alter the speed if it is outwith the permitted speed range (in your case 0-3 inclusive, using 0 as "stop"). Wouter's suggestion of an nenum is far better, however.
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic