- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Creating a Multilevel Inheritance Hierarchy in Java
Inheritance involves an object acquiring the properties and behaviour of another object. So basically, using inheritance can extend the functionality of the class by creating a new class that builds on the previous class by inheriting it.
Multilevel inheritance is when a class inherits a class which inherits another class. An example of this is class C inherits class B and class B in turn inherits class A.
A program that demonstrates a multilevel inheritance hierarchy in Java is given as follows:
Example
class A { void funcA() { System.out.println("This is class A"); } } class B extends A { void funcB() { System.out.println("This is class B"); } } class C extends B { void funcC() { System.out.println("This is class C"); } } public class Demo { public static void main(String args[]) { C obj = new C(); obj.funcA(); obj.funcB(); obj.funcC(); } }
Output
This is class A This is class B This is class C
Advertisements