‫Welcome back.
‫In this video, we'll talk about very important topic in Java, which is the inheritance.
‫Inheritance is one of the key features of Oop that allows you to create a new class from an existing
‫class.
‫The new class that is created is known as a subclass or child or derived class.
‫And the existing class from where the child class is derived is known as superclass or the parent or
‫base class.
‫The extends keyword is used to perform inheritance in Java.
‫Let's take a very quick example and understand the inheritance.
‫Let me create a vehicle class.
‫This vehicle class that represents the common features for all vehicles and then a car class that will
‫be a specific type of vehicle that will inherit the properties and methods from this vehicle class.
‫So this represents the parent class.
‫Now I'll create int number of wheels, variable of type int that represents the number of wheels of
‫this vehicle and I'll create the constructor alt plus insert to create the constructor, click okay.
‫And here in one second you can create the constructor.
‫This class will has two methods.
‫The first one is Start and the second one is stop.
‫When both methods call, there is a message will be appeared in the logcat that tells us the vehicle
‫starts and the vehicle stops respective.
‫Now let's create the child class, which is the car.
‫I'll create a new class and this class will represent the child class.
‫This car class extends a vehicle so it will inherit from vehicle superclass.
‫So this is the parent class and this is the child class.
‫We have an error here.
‫There is no default constructor available in vehicle.
‫I'll create matching create constructor matching soup.
‫But wait, what is the super keyword?
‫Is it referencing for Superman?
‫Absolutely.
‫No, the super keyword is a reference variable that it is used to access the immediate parent classes,
‫members, fields, methods and constructors.
‫It's often used in the context of inheritance.
‫When a subclass needs to refer to or call something from its super class.
‫And in this case, I want the car to get the number of wheels from the vehicle.
‫In this case, I can remove this and pass four because the cars in general have four wheels.
‫So this is an attribute number of wheels is four.
‫For all the cars, I can create another properties and properties specific for the car.
‫So car model and here I can pass the string modal car modal car modal or car modal equal to car modal.
‫And here I need this this keyword.