Current location: Hot Scripts Forums » Programming Languages » Everything Java » How to use Override annotation?


How to use Override annotation?

Reply
  #1 (permalink)  
Old 08-26-10, 11:32 PM
Learnbyexamples Learnbyexamples is offline
Disabled
 
Join Date: Jun 2010
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
How to use Override annotation?

Learning by examples
We use the @Override annotation as part of method declaration. The @Override annotation is used when we want to override methods and want to make sure have overriden the correct methods.
As the annotation name we know that there should be the same method signature in the parent class to override. That means using this annotation let us know earlier when we are mistakenly override method that doesn’t exist in the base class.

Code:
package org.kodejava.example.annotation;  
  
public class OverrideExample {  
    private String field;  
    private String attribute;  
  
    @Override  
    public int hashCode() {  
        return field.hashCode() + attribute.hashCode();  
    }  
  
    @Override  
    public String toString() {  
        return field + " " + attribute;  
    }  
}
How to use Override annotation?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Override request.form value loolweb ASP 1 12-07-06 10:53 AM


All times are GMT -5. The time now is 05:50 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.