this keyword in java this keyword in java with examples keyword this in java use of this keyword in java
this keyword in java with example this and super keyword in java use of this keyword in java with example use of this keyword in java inheritance use of this keyword in java constructor how to use this keyword in java this keyword in java example this keyword in java with example this keyword in java with example program explain this keyword in java with example super and this keyword in java use of super and this keyword in java use of super and this keyword in java with example difference between super and this keyword in java what is super and this keyword in java what is super and this keyword in java with example how to use this keyword in java with example
In java Accessing a variable , method, or any other data member of a class is
possible by
using object or reference. And the data members of any reference or object
can
be differentiate. And this differentiation can be divided into two types they
are:
1) This Keyword.
2) Super Keyword.
This Keyword:
This is one of the implicit variable /
keyword/object created by jvm supplied to each and every java program for two
purposes.
They are
a) It points to current class object.
b) Whenever the formal parameters and
data members of the class are similar, jvm gets an ambiguity. In order to
differ between formal parameters and data members of the class must be preceded
by keyword “this”.
this keyword is playing an important role in three places they are
1) this At variable level
2) this At Method level
3) this At Constructor level(this at constructor is one of the calling constructor process)
For Example:
Class demo
{
int a,b;
Demo(int a,int b)
{
this.a=a; //Here it to differ the
formal and data members
this.b=b; //Here it to differ the
formal and data members
}
}
Super keyword:
Super is one of the
keyword in java. Whenever we inherit base class details into
derived class,
there is possibility that base class features are similar to derived class
features and jvm gets an ambiguity. By using Super keyword to differentiate
between
based class features and derived class features, in context of derived
class the base
class features must be preceded by super keyword
Syntax:
Super.baseclassfeature;
If we are not writing super keyword before
the base class features are hidden in the context of derived class. Hence super
is keyword which differ the base and derived class features.
Similarly,Super
keyword is playing an important role in three places they are
1) Super At variable level
2) Super At method level
3) Super At constructor level (Super at constructor is one of the calling constructor process)
No comments:
Post a Comment