Delete comment from: Java67
From Java 1.5 onwards, an overridding method in Java can return sub-class of return type of overridden method. Which means if your original method return java.lang.Object than a method which overrides this in subclass can return object of Subclass. for example
public class Shape{
public Shape getShape(){
return new Shape();
}
}
public class Circle{
@OVerride
public Circle getShape(){
return new Circle();
}
}
is legal in Java 5, 6 and Java 7.
May 20, 2013, 10:07:41 PM
Posted to What is Method Overriding in Java ? Example Tutorial