0

Why there is static behind the method declaration?

can we declare method without static and can we access that?

9th Nov 2017, 2:18 AM
Waseem Siddiqi
Waseem Siddiqi - avatar
3 Answers
+ 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 } }
9th Nov 2017, 2:36 AM
Rrestoring faith
Rrestoring faith - avatar
+ 1
thank you so much
9th Nov 2017, 12:06 PM
Waseem Siddiqi
Waseem Siddiqi - avatar