Yes, It is possible to use this keyword to refer static members because this is just a reference variable which refers to the current class object. However, as we know that, it is unnecessary to access static variables through objects, therefore, it is not the best practice to use this to refer static members. Consider… Continue reading Can this keyword be used to refer static members?
Category: 5. OOPs Concepts: Inheritance Interview
Can we assign the reference to this variable?
No, this cannot be assigned to any value because it always points to the current class object and this is the final reference in Java. However, if we try to do so, the compiler error will be shown. Consider the following example. Output
What are the main uses of this keyword?
There are the following uses of this keyword. this can be used to refer to the current class instance variable. this can be used to invoke current class method (implicitly) this() can be used to invoke the current class constructor. this can be passed as an argument in the method call. this can be passed as an argument in the constructor call.… Continue reading What are the main uses of this keyword?
What is this keyword in java?
The this keyword is a reference variable that refers to the current object. There are the various uses of this keyword in Java. It can be used to refer to current class properties such as instance methods, variable, constructors, etc. It can also be passed as an argument into the methods or constructors. It can also be… Continue reading What is this keyword in java?