+ 3

what is the difference between static and final?

24th Sep 2016, 6:16 AM
Bimal Tirkey
Bimal Tirkey - avatar
4 Respostas
+ 13
When an attribute or method is declared as "static". It means that its a class attribute/method So it belongs to the class rather than a specific instance. You can access those class members via the class name. When final is used in class declaration is means that particilar class cant be inherited. When final is used with attributes, it means the value is constant and cant be changed. When final is used with methods, it means that method cant be overriden.
24th Sep 2016, 9:21 AM
Ousmane Diaw
+ 5
When we use use "final" key word with method thats mean we declare it as a constant and when we change its value, error accor. And when we use "static" key word with any method, its mean this method belongs to the class and we can access this by class
25th Sep 2016, 8:45 AM
Has Xan
Has Xan - avatar
0
it is meaningless to compare them. They are completely different things. Static makes your variable belongs to class and you can reach this variable from every instance of that class. If you add final keyword that makes your static variable to a constant. It is not a variable anymore, it is a constant and has an only one value. So, you can reach that constant every instant of this class.
10th Feb 2017, 3:57 AM
Sinan Ceylan
Sinan Ceylan - avatar
- 9
idk
27th Sep 2016, 3:46 AM
Devin