- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
instance variable hiding in Java
A local variable of same name will hide the instance variable. In order to use the instance variable, we should use the this operator. See the example below −
Example
public class Tester{ int a = 1; public static void main(String[] args) { Tester t = new Tester(); t.show(); t.show1(); } public void show(){ int a = 2; System.out.println(a); } public void show1(){ int a = 3; System.out.println(this.a); } }
Output
2 1
- Related Articles
- What is instance variable hiding in Java?
- Instance variable in Java
- Instance variable as final in Java
- Explain about field hiding in java?
- Instance variables in Java
- instance initializer block in Java
- Class that contains a String instance variable and methods to set and get its value in Java
- Static methods vs Instance methods in Java
- Custom instance creator using Gson in Java?
- Why use instance initializer block in Java?
- Data Hiding in Python
- What is method hiding in Java and how to use it?
- Final variable in Java
- How to create JShell instance programmatically in Java 9?
- What is the difference between method hiding and method overriding in Java?

Advertisements