JavaScript
  Home arrow JavaScript arrow Page 3 - 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: explanation


    (Page 3 of 5 )

    This section will explain the coding listed in the previous sections.  The class “First” is defined with the following members:

    • X
    • Y
    • setValues
    • getSum

    The class “Second” is defined with the following member:

    • getProduct

    As the class “Second” is inherited from “First,” it virtually contains the following members:

    • X
    • Y
    • setValues
    • getSum
    • getProduct

    Now the class “Third” is inherited from “Second.” Thus, it virtually contains the following members:

    • X
    • Y
    • setValues
    • getSum
    • getProduct
    • getDifference

    You can observe that all the members from the parent class (class “Second”) and grand parent class (class “First”), along with its own individual members are considered to be the members of the class “Third.” All this works behind the screen, magically!

    Now, if we proceed to our “test” frame, we have the following initially:

            Third obj1 = new Third();

    I declared an object “obj1” of type “Third.” 

    We display the difference of two values using the following code fragment:

            int r;
            r = obj1.getDifference();

    You can observe that I am calling the method “getDifference” without assigning any values to “x” and “y.” When the object of the class “Third” is created, the constructor of class “First” is executed followed by the class “Second.” So “x” and “y” are automatically assigned the values of 90 and 80 respectively. We display the difference of the two values using the following code fragment:

            this.lblMsg2.setText("Difference = " + String.valueOf(r));

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