InterviewSolution
Saved Bookmarks
| 1. |
Can this keyword be used to refer static members? |
|
Answer» This keyword cannot be used to refer to the static members of the CLASS. The reason is 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 members of the class can be accessed directly as no object is required. A program that demonstrates this is as follows: public class Demo { static INT a = 45; static int b; static void FUNC() { System.out.println("Static function"); b = a + 5; } public static void MAIN(String[] args) { func(); System.out.println("VALUE of a is: " + a); System.out.println("Value of b is: " + b); } }The output of the above program is as follows: Static function Value of a is: 45 Value of b is: 50 |
|