Welcome back friends, previously we have learned about inheritance in Java. And when we inherit from a different base classes or parent classes, there we face a certain situation, where we have a method with same name in the child and the parent class as well. So, how we can define which method or variable we are actually interested in using, we can use a specific keyword called Super, in that case, to resolve conflicts. And we are going to learn about this thing in detail here in this lecture. So let's talk a super key word is used in Java as a reference variable, which can be used to refer immediate parent of a class object. And we read parent class or we have multiple parents in a multi level inheritance and the super key word would point to direct or immediate pilot father or mother of the champions, not grand parents.
Whenever you create an instance of the sub class an instance or the parent class is created implicitly, which is referred by super new friends very directly. It is accessed by reading the keyword super separated by a dot. And then you can use the variable name automatically. Here we have the class parent, we have the child child accidental parents, and we both have the same variable called name after type is string. And we can point to the string a name method of the parent class using the super keyword super dot name What printer file we can assign well, so super can be used in different scenarios super can be used to refer to immediate parent class instance variable super can be used to invoke immediate parent class method. So what can we use to invoke immediate parent class constructor it can be used in case of variable method and constructor we have a class in written in Java and we can convert using a compiler into the class file.
When the class file gets created, we have to use a super method in order to access a super variable, any kind of thing, it gets executed as a first instinct when we have the immediate parent class that can be accessed from from the instance. Suppose we have an animal class we have a dog class dog classes a child class of animal class, and would have the same variable called color of Tiger strength. Or when we want to print the color of a dog class child class, we simply write it color. But if we want to print the value of color variable after base class or animal class, we have to write a super dark color. This will print the rally of color in the base class. Similarly, we can use for methods and different variables.
We can invoke emitted parent class methods using the super keyword as well. When we have both, when we have same method name it here in a child and parent classes, we can access a method from the base from the child class to the parent class using the super keyword, the super dot eat aggressive would would run the each method in the base class. Similarly, we can invoke immediate parent class constructor by simply writing super a followed by braces. We can write this keyword and initiate the constructor of the superclass. So this is a large, super super can be used in a wide range of cases. If and whenever you are using inheritance, you can use super to directly access the immediate parent.
Methods constructors and variables. Try building in our solution. Till then keep learning and keep moving ahead