Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

Inheritance in java with example

Inheritance is one of the concept of the Object- Oriented programming.

Inheritance in java with example

                          

Inheritance is one of the concept of the Object- Oriented programming. The advantage of using the inheritance is

  1. The reusability of the code.
  2. The helps to enhance the properties of the class.

It allows you to define a general class, and later more specialized classes by simply adding some new details. The properties of the parent class will automatically will be inherited by the base class.

The code of the program is given below:

 

 

<html>
    <head>
        <title>How to Use Inheritance in the  jsp</title>
    </head>
	<body>
        <h1>How to Use Inheritance in the  jsp</h1>
        <%!
            javax.servlet.jsp.JspWriter pw;
            class Rectangle
            {
				int length =10;
				int breadth =20 ;
                public int areaOfRectangle() throws java.io.IOException
                {
                    pw.println("Calculating the area of a rectangle...<br>");
					return(length*breadth);
                }
            }
            class Square extends Rectangle
            {
                public int areaOfSquare() throws java.io.IOException 
                {
                    pw.println("Calculating the area of a square...<br>");
					return(length*length);
                }
            }
        %>     
        <%
            pw = out;     
            Square sq = new Square();
            int area1 = sq.areaOfRectangle();
			out.println(area1);
			out.println("<br>");
            int area2 = sq.areaOfSquare();
			out.println(area2);
        %>
    </body>
</html>

The output of the program is given below:

Download this example.

                          

» View all related tutorials
Related Tags: java c library error ide io vi core tag lock this id action block write invoke like handle if solution

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.