✔ JAVA CHAPTERS:-
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
Association in Java: Previous Next: Aggregation in Java
Inheritance In Java
Inheritance is a way to implement IS-A relationship i.e. parent child relationship. Subclass inherits the subclass properties like data member, methods. Inheritance is the way of re-usability of code. Let us take the example of parent and child. A child inherits the properties of its parent.
Why inheritance is used?
- 1. Code re-usability.
- 2. Run-time polymorphism.
Syntax:
class subclass extends superclass{
//subclass code
}
|
Types of inheritance:
1. Single inheritance:
When a derived class inherits the properties and behavior from a single parent class. It is known as single inheritance.
Example:
Output:
2. Multilevel inheritance:
When a derived class inherits the properties and behavior from a derived class. It is known as multilevel inheritance.
Example:
Output:
3. Hierarchical inheritance:
When two or more derived class inherits the properties and behavior from same parent class. It is known as hierarchical inheritance.
Example:
Output:
Why multiple inheritance is not supported in java?
Multiple inheritance is not supported by Java because of ambiguity problem. Let us consider the below example. We have two classes Test1 and Test2 which have same method show(). If multiple inheritance is possible than Test class can inherit properties and behaviour of both Test1 and Test2 classes. Now Test class have two show() methods inherited from Test1 and Test2. Problem occurs now in method call, when show() method is called with Test class object which method will be called, of Test1 class or Test2 class. That is why multiple inheritance is not supported in java.