Published: 16 Jul 2020 › Updated: 16 Jul 2020
this Keyword In Java Programming
The following program source shows how this keyword is used to refer to instance variable of the class so as to avoid the confusion between the local variable and the instance variable.
public class ThisKeyword {
public static void main(String[] args) {
IntSum obj=new IntSum(5,6);
obj.displaysum();
}
}
class IntSum{
private int a;
private int b;
private int sum;
public IntSum(int a, int b) {
this.a=a;
this.b=b;
sum=a+b;
}
public void displaysum() {
System.out.println("The sum of the number is " + sum);
}
}
The output of this code is as below:
Leave this Keyword In Java Programming to:
Read more #java posts
Best Posts From Leo Umesh
We have not curated any of leoumesh's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Leo Umesh
- The Tattoo of My Newborn Baby Girl Forever Inked on My Skin
- Long Weekend Food Feast With Wife
- String Manipulation in C#: Part 2
- String Manipulation in C#
- Introduction to C# and .NET
- Weekend Escape To Falls
- Evening Barbecue With Favourite Beer 🍺 🍻
- NumPy Broadcasting
- Summer BBQ
- Review of "The Day of The Jackal" Series
- Wonders of Wave Rock, Western Australia
- Trying To Make Authentic Chicken Dum Biryani At Home
- Beautiful Ocean Lookout in South West Australia
- Esperance: Hidden Paradise of Western Australia
- Cruising Through Blue Haven Beach
- My First Tattoo
- Exploring Flavoursome Veggie Indian Cuisines
- Australia's Popular Drink: Homemade
- An Everlasting Flowers
- Unexpected Rainbow At Wellington Dam, Western Australia