The course is part of this learning path
In this course, we'll learn about object-oriented programming and its implementations.
Learning Objectives
- Inheritance
- Method Overriding
- Super and This Keywords
- Final Keyword
- Abstract Classes
- Interfaces
- Polymorphism
- Encapsulation
Intended Audience
- Anyone looking to get Oracle Java Certification
- Those who want to learn the Java Programming language from scratch
- Java developers who want to increase their knowledge
- Beginners with no previous coding experience in Java programming
- Those who want to learn tips and tricks in Oracle Certified Associate – Java SE 8 Programmer certification exams
Prerequisites
- No prior knowledge is required about the Java programming language
- Basic computer knowledge
Hi there, in this video, we will learn the types of Inheritance. There are some types of inheritance supported by Java. These are single inheritance, multilevel inheritance, hierarchical inheritance. You can use these inheritance types between Java classes. But apart from these, there are two more types of Inheritance: multiple inheritance, and hybrid inheritance. We can use multiple and hybrid inheritance types in interfaces, not Java classes, but we'll learn about them in this lesson. We'll make examples of these in our interface lesson. Now, let's look at what these inheritance types are in order. Single inheritance. When a class inherits another class, it's known as single inheritance. In the example given on the slide, the Car class inherits the Vehicle class. So, there is a single inheritance. Multilevel inheritance. In multilevel inheritance, a derived class will be inheriting a base class, and as well.
The derived class also acts as the base class for other classes. On this slide, class Vehicle serves as a base class for the derived class Car. Also, the Car class serves as a base class for the derived class Motorcycle. So, now the object of the Motorcycle class can access the properties of both Car and Vehicle classes. In Java, a class cannot directly access the grandparents members. Hierarchical inheritance. In hierarchical inheritance, one class serves as a superclass, base class for more than one subclass. On the slide, class Bicycle serves as a base class for the derived class MountainBike, RoadBike and TandemBike. Multiple Inheritance. In Multiple inheritances, one class can have more than one super class and inherit features from all parent classes.
On the slide, class Motorcycle is derived from interfaces A and B. Please note that Java does not support multiple inheritances with classes. In Java, we can achieve multiple inheritances only through interfaces. We'll learn about the interfaces in the upcoming lectures. Hybrid inheritance. It's a mix of two or more multiple inheritances. In the example, the Vehicle class is the super class. The Motorcycle and Car classes are the sub classes of the Vehicle class, but they are the subclass of the Scooter class. Since Java doesn't support multiple inheritances with classes, hybrid inheritance is also not possible with classes. In Java, we can achieve hybrid inheritance only through interfaces. Yes, these are the inheritance types. Let's take a short break here. See you in the next video.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.