JavaScript
  Home arrow JavaScript arrow Page 2 - Multi Level Class Inheritance in Java
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Multi Level Class Inheritance in Java
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2006-07-31

    Table of Contents:
  • Multi Level Class Inheritance in Java
  • An example of multi-level inheritance: code
  • An example of multi-level inheritance: explanation
  • Calling super class methods from a sub class: code and explanation
  • A more practical example of inheritance: code and explanation

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Multi Level Class Inheritance in Java - An example of multi-level inheritance: code


    (Page 2 of 5 )

    I already introduced single inheritance in my previous article. In this section, I shall introduce you to the concept of multi-level inheritance.

    Open your NetBeans project (as given in my previous article), and modify your code in “first.java” so that it looks something like the following:

      public class First {

          int x=0;
          int y=0;

          /** Creates a new instance of First */
          public First() {
              x = 10;
              y = 20;
          }

          public void setValues(int m, int n) {
              x = m;
              y = n;
          }

          public int getSum() {
              int t;
              t = x + y;
              return t;
          }
      }

    Modify your code in “second.java” so that it looks something like the following:

      public class Second extends First {

        /** Creates a new instance of Second */
        public Second() {
            x = 90;
            y = 80;
        }

        public Second(int m, int n) {
            x=m;
            y=n;
        }

        public int getProduct() {
            int p;
            p = x * y;
            return p;
        }
      }

    Now add a new class named “Third” using your NetBeans IDE. Modify your code in “Third.java” so that it looks something like the following:

      public class Third extends Second {

        /** Creates a new instance of Third */
        public Third() {
        }

        public int getDifference() {
            int p;
            p = x - y;
            return p;
        }
      }

    Now go back to the frame “test.java.” Double click on it to open and finally double click on the button to open the source view.  Within the source view, modify your “buttonActionPerformed” in such a way that it looks like the following:

      private void btnShowActionPerformed(java.awt.event.ActionEvent evt){
      // TODO add your handling code here:
            Third obj1 = new Third();
            int r;
            r = obj1.getDifference();
            this.lblMsg2.setText("Difference = " + String.valueOf(r));

        }
           

    The next section will explain all of the above code.

    More JavaScript Articles
    More By Jagadish Chaterjee


       · Hello guys. This is next contribution on OOPS with Java. enjoy
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT