Code.GeekInterview.com
 
 

Java Code Base

 
Code Samples Java
 

Multilevel Inheritance in Java


Code ResourceAuthor: Raju  

Difficulty Level:

Published: 4th Sep 2007   Read: 30921 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. srinivasaraobora234564
2. iamdvr137162
3. venki_madesh38441
4. Raju30922
5. Nidhi Saxena24605
6. Kiran.jakkaraju22994
7. parmod kumar duhan20659
8. yuvanmytri15658
9. venkat_kiran12379
10. chowsys11115

Active Coders

# Coder NameCodes
1. srinivasaraobora14
2. iamdvr3
3. Kiran.jakkaraju2
4. chowsys2
5. Nidhi Saxena1
6. Sindhukumar.R1
7. rakesh1
8. Raju1
9. Raju1
10. Raju1

Refined Tags