Runtime Polymorphism : Class in JSP Page « JSP « Java Tutorial






<HTML>
    <HEAD>
        <TITLE>Runtime Polymorphism</TITLE>
    </HEAD>

    <BODY>
        <H1>Runtime Polymorphism</H1>

        <%!
            javax.servlet.jsp.JspWriter localOut;

            class BaseClass
            {
                public void print() throws java.io.IOException 
                {
                    localOut.println("Hello from BaseClass...<BR>");
                }
            }

            class DerivedClass1 extends BaseClass
            {
                public void print() throws java.io.IOException 
                {
                    localOut.println("Hello from DerivedClass1...<BR>");
                }
            }

            class DerivedClass2 extends BaseClass
            {
                public void print() throws java.io.IOException 
                {
                    localOut.println("Hello from DerivedClass2...<BR>");
                }
            }

            class DerivedClass3 extends BaseClass
            {
                public void print() throws java.io.IOException 
                {
                    localOut.println("Hello from DerivedClass3...<BR>");
                }
            }
        %>     
        <%
            localOut = out;     
    
            BaseClass a1 = new BaseClass(); 
            DerivedClass1 b1 = new DerivedClass1(); 
            DerivedClass2 c1 = new DerivedClass2(); 
            DerivedClass3 d1 = new DerivedClass3(); 
            
            BaseClass baseClassVariable;
    
            baseClassVariable = a1;
            baseClassVariable.print();
    
            baseClassVariable = b1;
            baseClassVariable.print();
    
            baseClassVariable = c1;
            baseClassVariable.print();
    
            baseClassVariable = d1;
            baseClassVariable.print();
        %>
    </BODY>
</HTML>








23.14.Class in JSP Page
23.14.1.Using Inheritance
23.14.2.Using Restricted Access
23.14.3.Calling Superclass Constructors
23.14.4.Using Parameterized Constructors
23.14.5.Working With Constructors and Inheritance
23.14.6.Overloading Methods
23.14.7.Overriding Methods in derived class
23.14.8.Using Superclass Variables With Subclassed Objects
23.14.9.Runtime Polymorphism
23.14.10.Using Abstract Classes
23.14.11.Creating a Java Interface