I implemented this code:
class A {
//some code
}
class B extends A {
// some code
}
class C {
public static void main(String []args)
{
It's simple. Think that when you are extending you have to use is a
B `is a` A
A `is not` B
A more realistic example
class Animal{
}
class Dog extends Animal{
}
class Cat extends Animal{
}
A DOG IS A
Animal
AN ANIMAL IS NOT
a DOG necessary (Example : a cat is not a dog, and a cat is an animal)
You are getting runtime exception
cause , in runtime realize that that animal is not a dog, this is call downcasting
and is not safe what are you trying to do.