JSP Java


    
        Runtime Polymorphism
    
    
        

Runtime Polymorphism


        <%!
            javax.servlet.jsp.JspWriter localOut;
            class a
            {
                public void print() throws java.io.IOException 
                {
                    localOut.println("Hello from a...
");
                }
            }
            class b extends a
            {
                public void print() throws java.io.IOException 
                {
                    localOut.println("Hello from b...
");
                }
            }
            class c extends a
            {
                public void print() throws java.io.IOException 
                {
                    localOut.println("Hello from c...
");
                }
            }
            class d extends a
            {
                public void print() throws java.io.IOException 
                {
                    localOut.println("Hello from d...
");
                }
            }
        %>     
        <%
            localOut = out;     
    
            a a1 = new a(); 
            b b1 = new b(); 
            c c1 = new c(); 
            d d1 = new d(); 
            a baseClassVariable;
    
            baseClassVariable = a1;
            baseClassVariable.print();
    
            baseClassVariable = b1;
            baseClassVariable.print();
    
            baseClassVariable = c1;
            baseClassVariable.print();
    
            baseClassVariable = d1;
            baseClassVariable.print();
        %>