‫This keyword is a reference variable that it is used to refer to the current instance of the class.
‫It can be used within an instance method or a constructor to refer to the specific object that it is
‫invoking the method or creating the instance.
‫In this case, I am using this for referring for this car model.
‫So this car model is equal to the car model variable that it is passed as a parameter.
‫Inside this constructor car class, you can use this like if you have the same name of the variable
‫that it is passed and that it is created.
‫Or you can simply model of car, you can remove this and here I pass model of car.
‫So whenever you have different naming of variables, the variable, the local variable of this class
‫and the passed parameter of the constructor, you can get rid of this keyword.
‫Let's continue with the car class and I'll create a void honk method and this method will print as a
‫message, beep as a honk.
‫So in this example, the vehicle class is the parent class or base class, and the car class is the
‫child class that extends the vehicle class.
‫The vehicle class has a property called Number of Wheels and two methods start and stop methods.
‫The car class inherits these features from the vehicle class using the extends keyword.
‫The car class also has its own unique property called car model and a method called Honk, which represents
‫the sound of a car.
‫Now let's move to my class class and let's create objects and use them in the main method in order to
‫see the inheritance and the coloration between the car and the vehicle.
‫Let's start with car.
‫My car equal to new car.
‫And here I'll specify the model of car, the model of car 300, which is the Mercedes.
‫Now, if I call them the methods in this object and see the properties that I can access, I can see
‫that it is car.
‫It has the car model.
‫Absolutely.
‫Because it's the car itself.
‫The car class itself, number of wheels is the property that it is inherited from the vehicle.
‫Honk is the method that it is specific for the car class.
‫Start and stop are the methods that are inherited from the V and you can see that the methods or the
‫local methods of the car class and the local variables and local properties of the method are in bold.
‫So you can see car model and honk are the property and the methods that are included in the car class.
‫While the number of wheels start and stop are the methods and the properties that are inherited from
‫the vehicle.
‫Let's start with the start method.
‫My car dot honk and my car dot stop.
‫Let's run this program and here we go.
‫You can see the vehicle starts that it is inherited from the vehicle class.
‫Beep beep is from the car, which is the honk method and the vehicle stops, which is from the vehicle
‫class.
‫This is how inheritance works in Java.
‫The child class can reuse and extend the properties and methods of the parent class, making the code
‫more organized and easier to maintain.