I just started going for my bachelors degree in computer science(which means i have to rehash some basic concepts).and my teacher wanted us to show some coding examples of polymorphism. Here is my attempt. Would anyone like to show
any of their examples and or tips.![]()
Code:import java.util.*; public class X { public static void main(String[] args){ Vector v = new Vector(); v.addElement(new Superhero()); v.addElement(new Sidekick()); Iterator i = v.iterator(); while(i.hasNext()){ Superhero s = (Superhero)i.next(); s.printStatus(); } } } class Superhero { public void printStatus(){ System.out.println("I am the super hero!"); } } class Sidekick extends Superhero{ public void printStatus(){ System.out.println("I am a side kick!"); } }


and my teacher wanted us to show some coding examples of polymorphism. Here is my attempt. Would anyone like to show
Reply With Quote