This example shows how to use an Abstract Class in JSP.
We can create an Abstract Class and write it’s implementation in the Declaration Tag of JSP file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<HTML> <HEAD> <TITLE>Using Abstract Classes</TITLE> </HEAD> <BODY> <H1>Using Abstract Classes</H1> <%! javax.servlet.jsp.JspWriter localOut; abstract class a { abstract String getText() throws java.io.IOException; public void printem() throws java.io.IOException { localOut.println(getText()); } } class b extends a { String getText() throws java.io.IOException { return "Hello from JSP!"; } } %> <% localOut = out; b bObject = new b(); bObject.printem(); %> </BODY> </HTML> |