Code.GeekInterview.com
 
 

Java Code Base

 
Code Samples Java
 

Multilevel Inheritance in Java


Code ResourceAuthor: Raju  

Difficulty Level:

Published: 4th Sep 2007   Read: 31388 times  

Filed in: Java
Add Comment


 

 

Sponsored Links


 

 

This is a multilevel inhertance in java where number of methods can be created and accessed any where in the class a1 in the main class is the new object. here class A is inherited by both B and C i and j can be accessed from the method lmn.

 


Sample Code
  1.  
  2. *multilevel inheritance*/
  3. class A
  4. {
  5.         int i=10,j=20;
  6.         void xyz()
  7.         {
  8.                 System.out.println(i+j);
  9.         }
  10.         void lmn()
  11.         {
  12.                 System.out.println("lmn");
  13.         }
  14. }
  15. class B extends A
  16. {
  17.         int k=40,l=45;
  18.         void abc()
  19.         {
  20.                 System.out.println(i+j+k);
  21.                 lmn();
  22.         }
  23. }
  24. class C extends B
  25. {
  26. }
  27. class Inherit
  28. {
  29.         public static void main(String args[])
  30.         {
  31.         C a1= new C();
  32.         a1.abc();
  33.         }
  34. }
  35.  
Copyright GeekInterview.com


Next Article: Inheritance in Java


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. srinivasaraobora241796
2. iamdvr138719
3. venki_madesh38619
4. Raju31389
5. Nidhi Saxena25936
6. Kiran.jakkaraju23431
7. parmod kumar duhan20821
8. yuvanmytri16712
9. venkat_kiran12877
10. chowsys11294

Active Coders

Refined Tags