‫Welcome back.
‫In the last tutorial, we learned about inheritance.
‫The subclass inherits the attributes and methods of the superclass.
‫In this case, the vehicle is the superclass and the car inherits all the methods and attributes of
‫the vehicle.
‫Now, if the same method is defined in both the superclass and the subclass, then the method of the
‫subclass overrides the method of the superclass.
‫This is known as method overriding.
‫Let's take an example.
‫This is the method.
‫Start in the parent class or the superclass.
‫I'll override it in the car.
‫So let's go to here type void and you can see that Android studio like suggest for you start and stop
‫methods.
‫So if I click start you can see that this annotation at override will appear.
‫Notice the use of override annotation in this example in Java, annotations are the metadata that we
‫use to provide information to the compiler.
‫Here, The override annotation specifies the compiler that the method after this annotation overrides
‫the method of the superclass.
‫The start is a method that it is override by the car but inherited from the vehicle.
‫And you can see that Android studio will generate this hint one override.
‫We override it.
‫But what we benefit from it, let's say in the vehicle, the vehicle starts.
‫A message will appear when we call the method.
‫Start in the method start of the car, I'll remove super and create the car starts, not the vehicle.
‫Okay.
‫So when we call the start of the car class, it will print.
‫The car starts.
‫Let's go to my class, click run and you can see that when we call the start method of my car object,
‫it will print.
‫The car starts that it is overrided by the class car.
‫And if you notice that when we call the stop method that it is from vehicle but not override it in the
‫car class, it will print the message the vehicle stops, which is according to the stop method of the
‫vehicle, which is the superclass.
‫There are some rules for Java overriding concept.
‫Both the superclass and the subclass must have the same method name and the same return type and the
‫same parameter list.
‫So for example, the stop I can't create here void stop with capital letter and I'm I am calling it
‫as overriding because this method is different from this and Java is case sensitive.
‫So whenever I specify stop here, you can see that it is overriding by this symbol and it's not mandatory
‫to add the override annotation.
‫We can't override the methods declared as final and static and we should use override abstract methods
‫of the superclass.
‫So always override abstract methods of that class.
‫But what are abstracts?
‫In the next video, we'll talk about the abstraction.