0

Polymorphism/overriding

the first code is from polymorphism lesson and the 2nd code is from overriding lesson in the java course.what are the difference between the two codes?they look so similar. polymorphism https://code.sololearn.com/cf6YJ67Kze8m/?ref=app overriding https://code.sololearn.com/cnEXHKnXc7pA/?ref=app

23rd Oct 2017, 7:01 AM
oyl
4 Respuestas
+ 2
Story: A marker pen just went out of ink in class. Task: Find replacement, or new pen. Teacher: Mr. oyl, go to school supplies room and fetch me a new pen! #Override You: (In your mind) "I'll just borrow one from a nearby class" #Conclusion (Override): You "disobey", or totally ignore the actual method, and choose to have your own way to accomplish the task. #Overload You: "Sir, I can borrow one from nearby class, I can also get it from the teacher's room, it's nearer, I also have one with me here, we can just use this for now, yet, I can talk to the janitor to get one for you. What would you have me do sir?". #Conclusion (Overload): You improvise, provide your teacher other ways to accomplish the task, yet, you still will follow the actual method, despite you have the options. Your teacher then have more variants of how the pen can be fetched.
23rd Oct 2017, 8:55 AM
Ipang
0
@gordie so the only way to determine whether is it a polymorphism or a overriding is by looking at the instance code?"cat c=new cat" for overriding "animal c =new cat" for polymorphism.
24th Oct 2017, 12:09 AM
oyl