CodesJava

Easy learning with example program codes

Override Java Annotation


Dictionary meaning of Annotation

Annotation refers to a note by way of explanation or comment added to a text or diagram.

Java Annotations:

Java annotations are used to provide the meta data to our Java code. Meta data is the additional information which can be used for any class, interface, method or field. Java annotations can be used as an alternative option for XML and java marker interfaces. Java annotations were added to Java from Java 5.

@Override java annotation:

The @Override java annotation indicates that the subclass method is overriding the parent class method. Compile time error occurs if it not overrides the specified method. As override annotation is not mandatory to use while overriding the method so if we are not using override annotation it may be the case someone changed the name of the overridden method in the superclass. In that case subclass method would no longer override it. So we always have to use @Override annotation which signals the compiler that the method in the subclass is not overriding any method in the superclass.

package com.tutorialspointexamples;
 
class ParentClass{  
	void display(){
		System.out.println("Parent Class Display Method.");
	}  
}  
 
public class SubClass extends ParentClass{
	@Override
	void display(){
		System.out.println("Sub Class Display Method.");
	}
	public static void main(String args[]){
		SubClass obj = new SubClass();
		obj.display();
	}
}

Output:

Sub Class Display Method.

Download this example.

Sign Up/ Sign In
Ask a Question


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki