Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 27th, 2010, 12:32 AM
EliteHussar
Guest
 
Posts: n/a
Default 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?





Similar Threads
Thread Thread Starter Forum Replies Last Post
What is @Override for? Whoelse BOOK: Professional Android 2 Application Development 4 July 9th, 2010 01:51 AM
Why would you override ToString()? chobo2 C# 2008 aka C# 3.0 16 November 11th, 2008 11:01 PM
how to override equals() and hashcode() praveena Java Basics 3 March 14th, 2006 02:30 AM
To Override or Not to Override frresh BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 May 2nd, 2005 01:33 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.