+ 1

Use of this keyword in Java

What is the use of this keyword when we call a static function without creating an object?

15th Jun 2020, 6:30 AM
Souptik Nath
Souptik Nath - avatar
3 Respostas
+ 2
static - 'Class members' (variables, methods) can be referenced by ClassName.memberName similar like non-static by objectName.memberName or this.memberName (inside class definition)
15th Jun 2020, 7:37 PM
zemiak
+ 1
public class Program { static int x; static void method(int x){ Program.x = x; } public static void main(String[] args) { Program.method(100); System.out.println( Program.x ); } }
15th Jun 2020, 4:16 PM
zemiak
+ 1
zemiak Can You Please explain? Specially what is the use of classname.variablename?
15th Jun 2020, 4:34 PM
Souptik Nath
Souptik Nath - avatar