CIS 26
Object-Oriented Programming
Polymorphism

Consequenceas of Polymorphism

Some Preliminaries

Polymorphic assignment

Why upcast?

Why downcast?

  • Assigning from a method that returns a supertype

    Polymorphic method invocation

    Putting it All into Perspective

    class MyApplet extends Applet {
    	...
    }
    
  • browser creates a MyApplet object and assigned it to an Applet object
    	Applet app = Applet.load("MyApplet.class"); // rhs returns an object 
    						// of type MyApplet
    
  • Then the browser invokes init
    app.init();			
    		
  • And voila, control is passed to MyApplet!!