<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>
Saturday, 17 December 2011
JSP Examples Tutorial - Runtime Polymorphism
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment