image
Types of Inheritance
Start course
Difficulty
Beginner
Duration
1h 46m
Students
22
Ratings
5/5
Description

In this course, we will learn the concepts of microservice and spring framework with a focus on inheritance.

Learning Objectives

  • Inheritance in Java

Intended Audience

  • Beginner Java developers
  • Java developers interested in learning how to Build and Deploy RESTful Web Services
  • Java Developers who want to develop web applications using the Spring framework
  • Java Developers who want to develop web applications with microservices
  • Java Developers who wish to develop Spring Boot Microservices with Spring Cloud

Prerequisites

  • Basic Java knowledge
Transcript

Hello there, my friends. 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 in Java classes, but we will learn about them in this lesson. We will demonstrate these in our interface lesson. So, for now let's look at what these inheritance types are in order. Single inheritance. When a class inherits another class, it is known as a single inheritance. In the example given on the slide, the Car class inherits the Vehicle class, so there is single inheritance. Multilevel inheritance. In multilevel inheritance, a derived class will be inheriting a base class and the derived class also acts as the base class for other classes. On the slide, class Vehicle serves as a base class for the derived class Car.

Also, the Car class serves as a base class for the drive 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 grandparent's 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 superclass and inherit features from all parent classes. On the slide, class Motorcycle is derived from interfaces A and B. So, I just want to take a moment to 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 superclass, the Motor class and Car classes are the subclasses of the Vehicle class, but they are the superclass 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. So, these are the inheritance types. Let's take a short break here and I'll see you in the next video my friends.

 

About the Author
Students
3918
Courses
64
Learning Paths
5

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.