The Output of below statement is correct because
((AClass)b).m(); // Does compile and return B\nSuper:\nA
There are two things happening
one is compile time
polymorphism.
It's happening because you are doing BClass object type cast with AClass object so this thing checked at compile time.
second run time polymorphism.
At run time even you are using sub class object with super class reference it'll call sub class object method.
You are getting compile time error at
b.m(); // Does not compile
line because method m access modifier is protected and you can not use out of protected member out side the package without using inheritence.