java - just a quick thing about polymorphism -
say class classone
extends classtwo
, classone
subclass , classtwo
superclass. if went class , typed in: classtwo hello = new classone();
mean can use methods in classone
have been inherited classtwo
, not methods in classone
? (e.g a. method called void eat();
in classtwo
, classone
inherited method void walk();
in classone
, not in classtwo
using hello
keyword, access eat function , not walk function?), don't quite understand concept of polymorphism. can explain , giving example? much.
yes true, system see classone
classtwo
in regards available methods. think these concept buckets, in case classone
fits classtwo
bucket. if put classone
in classtwo
bucket can see classtwo
bucket. pick out classone
classtwo
bucket, can cast it.
this helps in case of upcasting , downcasting, casting object supertype or subtype. either put item in basket(upcasting) or take out basket (downcasting).
this analogy might crap helps me :)
to answer question yes, can't make method-call method in classone
if casted classtwo
.
this handy anf many times preferable. think of interfaces
, interface tells object provide set of methods. way can ensure these methods available calling object, contract object has it's surroundings.
also possible duplicate: try describe polymorphism easy can
Comments
Post a Comment