+ 4

What is difference between class varibales and local variables..??

20th Nov 2017, 5:58 PM
Ajay Gaikwad
Ajay Gaikwad - avatar
3 odpowiedzi
+ 1
m looking for someone who can teach me Java script my WhatsApp number is +243840461536
26th Jan 2018, 12:21 PM
Omari Franz
Omari Franz - avatar
0
A class variable is declared inside the class and it's visible to all methods and other variables as well (if It's public). A local variable is declared inside a method (and consider that method can be outside the class you aim). This variable is only used by that method and only when the method is called
20th Nov 2017, 11:54 PM
Jonathan Álex
Jonathan Álex - avatar
0
ex: public static class Class1{ public static void print10( ){ private int value = 10; System.out.println(value); } public class Class2{ public static void main(String [ ] args){ int otherValue = 20; System.out.println(otherValue); print10( ); } } in this example, you can't use directly or change the value of the variable "value" from the main class, because It's a local variable from the Class1, but you can use or change the value of the variable "otherValue" as well, because it's a class variable of the Class2 (the main class).
21st Nov 2017, 12:08 AM
Jonathan Álex
Jonathan Álex - avatar