- 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
Can a "this" keyword be used to refer to static members in Java?
No, the "this" keyword cannot be used to refer to the static members of a class. This is because the “this” keyword points to the current object of the class and the static member does not need any object to be called. The static member of a class can be accessed directly without creating an object in Java.
Example
public class StaticTest { static int a = 50; static int b; static void show() { System.out.println("Inside the show() method"); b = a + 5; } public static void main(String[] args) { show(); System.out.println("The value of a is: " + a); System.out.println("The value of b is: " + b); } }
Output
Inside the show() method The value of a is: 50 The value of b is: 55
Advertisements