Dynamic vs static | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Dynamic vs static

Can someone help me to understand better when we use a dynamic class or a static class in Java?

18th Mar 2021, 7:59 AM
Zotta
Zotta - avatar
2 Answers
+ 1
class SomeClass { private int a; static int pow2(int n) { return n*n; } void seta(int a) { this.a = a; } } if a method use variable that has different values in each instantiation of this class, the method can't be static. ( here seta() ) A static method can be used eg to create a new object. Integer oi = Integer.valueOf(100)
18th Mar 2021, 7:15 PM
zemiak
18th Mar 2021, 8:21 AM
Rik Wittkopp
Rik Wittkopp - avatar