This Keyword in JAVA

Posted By on September 16, 2014


Download PDF
JAVA Question Bank
Super Keyword

this  is a keyword in Java. Which can be used inside method or constructor of  class. It(this) works as a reference to current object whose method or constructor is being invoked. this keyword can be used to refer any member of current object from within an instance method or a constructor.

this keyword with field(Instance Variable)

this keyword can be very useful in case of Variable Hiding. We can not create two Instance/Local Variable with same name. But it is legal to create One Instance Variable & One Local Variable or Method parameter with same name. In this scenario Local Variable will hide the Instance Variable which is called Variable Hiding.

Example of Variable Hiding

Output of the above programme

JAVA Question Bank
Super Keyword

Download PDF

Posted by Akash Kurup

Founder and C.E.O, World4Engineers Educationist and Entrepreneur by passion. Orator and blogger by hobby

Website: http://world4engineers.com