0
Why there is static behind the method declaration?
can we declare method without static and can we access that?
3 odpowiedzi
+ 7
Yes we can make methods non-static.
You can only access something that is not static from an Object reference.
Some examples:
public class Program{
public static void main(String[] args){
Program obj = new Program();
obj.myMethod(); // OK
myMethod(); // ERROR
}
void myMethod(){}
}
class myClass(){
void method1(){
method2(); // OK
}
void method2(){
method3(); // OK
}
static void method3(){
method2(); // ERROR
}
}
+ 1
thank you so much