0% found this document useful (0 votes)
75 views3 pages

Command Line Argument

The document discusses the 'this' and 'super' keywords in Java. The 'this' keyword refers to the current object in a method or constructor and is commonly used to distinguish between class attributes and parameters with the same name. The 'super' keyword is used to refer to the immediate parent class and can be used to access parent variables, methods, and invoke the parent constructor.

Uploaded by

Faizan Dange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views3 pages

Command Line Argument

The document discusses the 'this' and 'super' keywords in Java. The 'this' keyword refers to the current object in a method or constructor and is commonly used to distinguish between class attributes and parameters with the same name. The 'super' keyword is used to refer to the immediate parent class and can be used to access parent variables, methods, and invoke the parent constructor.

Uploaded by

Faizan Dange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

“this” and “super “

Keywords
in Java
“this” Keyword
The this keyword refers to the current object in a method or constructor.
The most common use of the this keyword is to eliminate the confusion
between class attributes and parameters with the same name (because a class
attribute is shadowed by a method or constructor parameter).
public class MyClass
{
int x;
// Constructor with a parameter
public MyClass(int x)
{ this.x = x;
} // Call the constructor
public static void main(String[] args)
{ MyClass myObj = new MyClass(5);
System.out.println("Value of x = " + myObj.x);
}
}
“super” Keyword
“super” keyword is reference variable which is used to refer immediate
parent class object.

Uses of “super” keywords


1. “super” keyword can be used to refer immediate parent class instance
variable.
2. “super” keyword can be used to invoke immediate parent class
method.
3. super() can be used to invoke immediate parent class constructor.

You might also like