I implemented this code:
class A {
//some code
}
class B extends A {
// some code
}
class C {
public static void main(String []args)
{
The fact that B extends A means that B is A, i.e. B is like A but probably add some other stuff.
The opposite is wrong. A is not B. Therefore you cannot cast A to B.
Think this way. A is Animal. B is Bee. Is Bee animal? Yes it is. Is any animal Bee? Not it is not. For example Dog is animal but definitely not a Bee.