![]() It is used to refer to an instance variable of an immediate parent class.We cannot use the “ super” keyword as an identifier in Java. Using the “ super” keyword, we can refer to the immediate parent class's methods, constructor, instance variables, and many more. “ super” is a special keyword in Java that is used to refer to the instance of the immediate parent class. What is used wants to use the methods of class A in class B? We solve this issue using the super keyword. Similarly class C extends class B and now class C has two parents i.e., class A and class B, where class B is immediate parent of class C. In the above code snippet of multi-level inheritance class B extends class A, it implies class A is immediate parent of class B. Let me explain the term immediate parent. Also we can differentiate between the variables that are declared inside the classes and methods. By this we can change the values of the variables that are declared inside the class. The “ this” keyword is referring to an instance and a static variable in the same class. It is used to initiate a constructor of the current class.Įxample of this keyword in Java Example 1.It can be passed as an argument in the constructor call. ![]() It refers to an instance variable and static variable of the current class.It can be used to return the current class instances.It can be passed as an argument in the method call.We cannot use the “ this” keyword as an identifier in Java(identifier is name given to any method, class, package, etc.). Using the “ this” keyword, we can refer to the current class's methods, constructor, instance variables, and many more. “ this” is a special keyword in Java that is used to refer to the instance of the current class. ![]() In technical terms we are using this keyword tw refer the instance of current class. If we want to assign the value of parameter 'var' to the variable 'var' inside the class then we have to use the this keyword. As we can see that we have a variable 'var' and a parameter 'var' inside the method function. Let us under the use of this keyword using the above code snippet. This is possible only when one class inherits another class(child class extends parent class). Super: super is the reserved keyword in Java that is used to invoke constructor, methods of the parent class. This: this is the reserved keyword in Java that is used to invoke constructor, methods, static members of the current class. “ this” and “ super” are used to resemble the reference variable pointing to sub-class or parent class (superclass). Java provides many implicit keywords among those “ this” and “ super” are two reference variables.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |