class Animal {
long eat() {
System.out.println("i am in class Animal");
return(0);
}
}
class Horse extends Animal {
int eat() {
System.out.println("i am in horse");
return(0);
}
}
class Pg100 {
public static void main(
String[] args) {
Animal a = new Animal();
Animal b = new Horse();
long x = a.eat();
int y = b.eat();
}
}
output:
F:\j5se\kathy>javac Pg100.java
Pg100.java:9: eat() in Horse cannot override eat() in Animal; attempting to use incompatible return type
found : int
required: long
int eat() {
^
Pg100.java:20: possible loss of precision
found : long
required: int
int y = b.eat();
^
2 errors
Here return type is long in Animal class & int in Horse class, and both are integeral type & what i think is int is subtype of long.