I have this code:

```
package Maven_test.Maven_project_test;

public class Test {
    class A {
        int i = 10;
    }

    class B extends A {
        int j = 20;
    }

    class C extends B {
        int k = 30;
    }

    public void pruebaJerarquia() {
        A a = new B();
        B b = (B) a;
        C c = (C) b;

        System.out.println(c.k);
    }
}

```

and I'd like to know why this line:

```
C c = (C) b;

```

throws this exception when executing the program:

```
Exception in thread "main" java.lang.ClassCastException: 
Maven_test.Maven_project_test.Test$B cannot be cast to 
Maven_test.Maven_project_test.Test$C
    at Maven_test.Maven_project_test.Test.pruebaJerarquia(Test.java:21)
    at Maven_test.Maven_project_test.App.main(App.java:10)

```

I think it has something to do with upcasting and downcasting, but I don't get it. Could it be because "b" is pointing to "a" and with "C c = (C) b" it's like trying to cast something like this?

```
C c = new A();

```

Thank you!