I m Beginner in Java, so someone please say how to call methodA() in Animal Through Mammal object.i cant understand why we need Downcasting and Upcasting clearly.
class Animal{
void methodA(){
System.out.println("I m Animal");
}
}
class Mammal extends Animal{
void methodA(){
System.out.println("I m Mammal child class of Animal");
}
void methodAB(){
System.out.println("Two child class Dog and Cat I have");
}
}
public class UpDownCast {
public static void main(String[] args) {
Animal a = new Animal();
a.methodA();
Mammal m = new Mammal();
m.methodA();
Animal A = new Mammal();
if (A instanceof Mammal){
A.methodA();
}
Animal A1= new Animal();
Mammal M1 =(Mammal)A1;
M1.methodA();
}
}
Thanks in Advance.