Google+

106. 'Multilevel' Hierarchy






Till now we have worked on a single level hierarchy ( i.e. a subclass inheriting all the members of a superclass) . But we can create multiple levels of hierarchy (i.e. for example - class2 inheriting all the members of class1 and class3 inheriting all the members of class1 and class2).

Lets implement this on Eclipse IDE:

1.Create a superclass 'ClassOne' as shown below:



2. Create  a subclass 'ClassTwo' for superclass 'ClassOne' as shown below:



3. Create a subclass 'ClassThree' for super-classes 'ClassOne' and 'ClassTwo' as show below:



4. Create another class 'MultiLevelHierarchyDemo' to access the local and inherited members of subclass 'ClassThree' as shown below:



5. Save and Run the 'MultiLevelHierarchyDemo' class
6. Observe that the output is displayed in the console as shown below:



Download this project:

Click here to download this project containing 'ClassOne', 'ClassTwo', 'ClassThree' and 'MultiLevelHierarchy' class files used in this post (You can download this project and import into Eclipse IDE on your machine)




Please comment below to feedback or ask questions.

Using 'super' keyword in Multilevel hierarchy will be explained in the next post. 



No comments: