JavaScript
  Home arrow JavaScript arrow Page 4 - 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 - Calling super class methods from a sub class: code and explanation


    (Page 4 of 5 )

    In this section, we will look at calling super class methods from a sub class using multi-level inheritance. The same issues apply to single inheritance.

    Now, open the class “Third” (available in “third.java”) and modify the code in such a way that it looks like the following:

      public class Third extends Second {

        int z;

        /** Creates a new instance of Third */
        public Third() {
            z=50;
        }

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

        public int getProductOfAll() {
            return ((super.getProduct()) * z);
        }
    }

    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.getProductOfAll();
            this.lblMsg2.setText("Product = " + String.valueOf(r));
        }
                   

    From all of the above code, the only important issue to discuss is the following method:

      public int getProductOfAll() {
            return ((super.getProduct()) * z);
        }

    This method simply calls another method, “getProduct,” which belongs to its super class.  As “getMethod” returns an integer, it can be multiplied with “z” and again return the same.

    In this case, the word “super” in the code is not essential.  But makes the code more readable.

    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 4 hosted by Hostway
    Stay green...Green IT