<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>
Showing posts with label jsp access. Show all posts
Showing posts with label jsp access. Show all posts
Saturday, 17 December 2011
JSP Examples Tutorial - Working With Constructors and Inheritance
JSP Examples Tutorial - Using Superclass Variables With Subclassed Objects
<HTML> <HEAD> <TITLE>Using Superclass Variables With Subclassed Objects</TITLE> </HEAD> <BODY> <H1>Using Superclass Variables With Subclassed Objects</H1> <%! javax.servlet.jsp.JspWriter localOut; class BaseClass { public void start() throws java.io.IOException { localOut.println("Starting...<BR>"); } } class DerivedClass1 extends BaseClass { public void fly() throws java.io.IOException { localOut.println("Flying...<BR>"); } } class DerivedClass2 extends DerivedClass1 { public void fly() throws java.io.IOException { localOut.println("Flying...<BR>"); } } %> <% localOut = out; out.println(); out.println("Creating a DerivedClass2 object...<BR>"); BaseClass p = new DerivedClass2(); p.start(); %> </BODY> </HTML>
JSP Examples Tutorial - Using Restricted Access
<HTML> <HEAD> <TITLE>Using Restricted Access</TITLE> </HEAD> <BODY> <H1>Using Restricted Access</H1> <%! javax.servlet.jsp.JspWriter localOut; class BaseClass { protected void start() throws java.io.IOException { localOut.println("Starting...<BR>"); } } class DerivedClass extends BaseClass { public void drive() throws java.io.IOException { localOut.println("Driving...<BR>"); } } %> <% localOut = out; out.println("Creating an DerivedClass...<BR>"); DerivedClass a = new DerivedClass(); a.start(); a.drive(); %> </BODY> </HTML>
Subscribe to:
Posts (Atom)