<HTML>
<HEAD>
<TITLE>Runtime Polymorphism</TITLE>
</HEAD>
<BODY>
<H1>Runtime Polymorphism</H1>
<%!
javax.servlet.jsp.JspWriter localOut;
class a
{
public void print() throws java.io.IOException
{
localOut.println("Hello from a...<BR>");
}
}
class b extends a
{
public void print() throws java.io.IOException
{
localOut.println("Hello from b...<BR>");
}
}
class c extends a
{
public void print() throws java.io.IOException
{
localOut.println("Hello from c...<BR>");
}
}
class d extends a
{
public void print() throws java.io.IOException
{
localOut.println("Hello from d...<BR>");
}
}
%>
<%
localOut = out;
a a1 = new a();
b b1 = new b();
c c1 = new c();
d d1 = new d();
a baseClassVariable;
baseClassVariable = a1;
baseClassVariable.print();
baseClassVariable = b1;
baseClassVariable.print();
baseClassVariable = c1;
baseClassVariable.print();
baseClassVariable = d1;
baseClassVariable.print();
%>
</BODY>
</HTML>
|