Saturday, 17 December 2011

JSP Examples Tutorial - Working With Constructors and Inheritance


<HTML>
    <HEAD>
        <TITLE>Working With Constructors and Inheritance</TITLE>
    </HEAD>
    <BODY>
        <H1>Working With Constructors and Inheritance</H1>
        <%!
            javax.servlet.jsp.JspWriter localOut;
 
            class BaseClass
            {
                BaseClass() throws java.io.IOException 
                {
                    localOut.println("In a\"s constructor...<BR>");
                }
                BaseClass(String s)  throws java.io.IOException
                {
                    localOut.println("In a\"s String constructor...<BR>");
                    localOut.println(s);
                }
            }
 
            class DerivedClass extends BaseClass  
            {
                DerivedClass(String s) throws java.io.IOException 
                {
                    super(s);
                    localOut.println("In b\"s String constructor...<BR>");
                    localOut.println(s);
                }
            }
        %>     
        <%
            localOut = out;     
            DerivedClass obj = new DerivedClass("Hello from JSP!<BR>");
        %>
    </BODY>
</HTML>

No comments:

Post a Comment