Home arrow JavaScript arrow Page 3 - Multi Level Class Inheritance in Java
JAVASCRIPT

Multi Level Class Inheritance in Java


In this article, I shall provide an introduction to multi-level inheritance when programming with OOPS in Java using NetBeans IDE. I will also cover calling methods of the super class, and discuss a simple, practical example.

Author Info:
By: Jagadish Chaterjee
Rating: 3 stars3 stars3 stars3 stars3 stars / 19
July 31, 2006
TABLE OF CONTENTS:
  1. · Multi Level Class Inheritance in Java
  2. · An example of multi-level inheritance: code
  3. · An example of multi-level inheritance: explanation
  4. · Calling super class methods from a sub class: code and explanation
  5. · A more practical example of inheritance: code and explanation

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

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));


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials