Java/JSP/Overloading Methods
Версия от 18:01, 31 мая 2010; (обсуждение)
Overloading Methods
<HTML>
<HEAD>
<TITLE>Overloading Methods</TITLE>
</HEAD>
<BODY>
<H1>Overloading Methods</H1>
<%!
javax.servlet.jsp.JspWriter localOut;
void printText() throws java.io.IOException
{
localOut.println("Hello!<BR>");
}
void printText(String s) throws java.io.IOException
{
localOut.println(s + "<BR>");
}
%>
<%
localOut = out;
printText();
printText("Hello from JSP!");
%>
</BODY>
</HTML>
Overriding Methods 2
<HTML>
<HEAD>
<TITLE>Overriding Methods</TITLE>
</HEAD>
<BODY>
<H1>Overriding Methods</H1>
<%!
javax.servlet.jsp.JspWriter localOut;
class animal
{
public void breathe() throws java.io.IOException
{
localOut.println("Breathing...<BR>");
}
}
class trout extends animal
{
public void breathe() throws java.io.IOException
{
localOut.println("Gilling...<BR>");
}
}
%>
<%
localOut = out;
out.println("Creating an animal object...<BR>");
animal a = new animal();
a.breathe();
out.println();
out.println("Creating a trout object...<BR>");
trout t = new trout();
t.breathe();
%>
</BODY>
</HTML>