Reader Level:
ARTICLE

Using Superclass Variables with Subclassed Objects in JSP

Posted by Vikas Mishra Articles | JSP February 07, 2012
In this article we are using Superclass Variables With Subclassed Objects In JSP.
  • 0
  • 0
  • 5390
Download Files:
 

Super Class

In Java, there is a concept of Inheritance which is implemented through a superclass and subclass definition and achieved through the object creation process, programmatically. Inheritance allows to organize and structure the software program in an hierarchical manner through the concept of super class and subclass. Through inheritance a new class inherits some existing behavior and states of another class which is called the superclass. This promotes the concept of code reusability. Creation of a superclass saves work as the already existing class allows the new class to inherit all the properties of the old general class.

Sub Class

In Java, as in other object-oriented programming languages, classes can be derived from other classes. The derived class (the class that is derived from another class) is called a subclass. The class from which its derived is called the superclass.

Here we are going to develop an application using Superclass Variables with Subclassed Objects in JSP. To develop this application we use the following steps.

Step 1 : Create a New Project.

In this step we select New Project option from file menu.

create new project.jpg

Step 2 : Choose Project.

In this step we select a web application from the Java web option and then click on the next Button.

select new web application.jpg

Step 3 : Name and Location.

In this step we give it a specific name and set a specific location and click on the next Button.

name.jpg 

Step 4 : Server and Setting.

We select a specific server for this application and click on the next Button.

server and setting.jpg

Step 5 : Select Framework.

There is no need to select any framework for this application; just click on the finish button.

selectframework.jpg

Step 6 : Create jsp file.

We create one jsp file for this application.

create new jsp file.jpg

index.jsp

<HTML>
        <HEAD>
        <TITLE>
Using Superclass Variables With Subclassed Objects In JSP</TITLE>
        </HEAD>
        <BODY
BGCOLOR="cyan">
                 <H1>Using Superclass Variables With Subclassed Objects In JSP</H1>
                 <%!
                      javax.servlet.jsp.JspWriter localValue;
                      class vehicle
                        {
                          public void start() throws java.io.IOException
                          {
                           localValue.println("Starting with jsp...<BR>");
                         }
                           }

                     class aircraft extends vehicle
                      {
                        public void fly() throws java.io.IOException
                          {
                           localValue.println("Flying...<BR>");
                          }
                      }

                    class plane extends aircraft
                     {
                       public void fly() throws java.io.IOException
                        {
                          localValue.println("Flying...<BR>");
                        }
                     }
                  %>
                  <%
                      localValue = out;
                       out.println();
                       out.println("Creating a plane object in JSP...<BR>");
                       vehicle p = new plane();
                       p.start();
                  %>
          </BODY>
</HTML>



Step 7 :
Compile and Run the application.

Now we compile the application and then run it on the server and find the following output.

Output

index.jsp

output.jpg

Resources related to this topic

COMMENT USING

Trending up