Code.GeekInterview.com
 
 

Java Code Base

 
Code Samples Java
 

Multilevel Inheritance in Java


Code ResourceAuthor: Raju  

Difficulty Level:

Published: 4th Sep 2007   Read: 30049 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. srinivasaraobora206743
2. iamdvr132662
3. venki_madesh37887
4. Raju30050
5. Kiran.jakkaraju21787
6. Nidhi Saxena21474
7. parmod kumar duhan20212
8. yuvanmytri13420
9. venkat_kiran11105
10. chowsys10572

Active Coders

Refined Tags