Can this keyword be used to refer static members in Java?
Yes, It is possible to use this keyword to refer static members because this is just a reference variable which refers to the current class object. However, as we know that, it is unnecessary to access static variables through objects, therefore, it is not the best practice to use this to refer static members. Consider the following example.
- public class Test
- static int i = 10;
- public Test ()
- public static void main (String args)
- Test t = new Test();