JSP Java Tutorial

< HTML>
    
        Using Superclass Variables With Subclassed Objects
    
    
        

Using Superclass Variables With Subclassed Objects


        <%!
            javax.servlet.jsp.JspWriter localOut;
            class BaseClass
            {
                public void start() throws java.io.IOException 
                {
                    localOut.println("Starting...
");
                }
            }
            class DerivedClass1 extends BaseClass
            {
                public void fly() throws java.io.IOException 
                {
                    localOut.println("Flying...
");
                }
            }
            class DerivedClass2 extends DerivedClass1
            {
                public void fly() throws java.io.IOException 
                {
                    localOut.println("Flying...
");
                }
            }
        %>     
        <%
            localOut = out;     
            out.println();
            out.println("Creating a DerivedClass2 object...
");
            BaseClass p = new DerivedClass2();
            p.start();
        %>