Hi,
In KS&BB book,it is written that in method overriding...whatever the superclass declares as a return type,the overriding method must declare either
the SAME type,or a SUBCLASS type..
keeping that in mind..i have overrided the SuperClass method display() by changing its return type..but it is showing error that we cant overide in this way... can ny1 figure out where i have done wrong?
class SuperClass {
public int display(){
System.out.println(" In SuperClass method.");
return 1;
}
}
public class Method_Overriding extends SuperClass{
public short display(){
System.out.println(" In Overriding method.");
return ( (short)1);
}
public static void main(
String[] args) {
SuperClass sc1 =new Method_Overriding();
sc1.display();
}
}