I have a class A and class B which extends A and is a subclass. Now i have
A aObject = new A(); and
A bObject = new B();
Now can i call the method in class B which is not in A using bObject without typecasting ?
If we cant do so without typecasting, what is the advantage of polymorphism then?
Thanks.
No, you cannot. On both objects
aObjectandbObjectyou can call only methods that are defined forAwithout using casting.If you defined
bObjectto be of typeB, then you could, but as your code stands you can only work withA‘s methods and members.