+ 1

About static method in java

I know mean of static and know that If we have static method variable inside this method must be static as variable is copying But question What about method not static inside method static Why i can't make this

6th Sep 2019, 12:07 AM
Mahmoud Salama Sleem
3 Réponses
+ 3
Suppose you have a class and you haven't created any object yet. This will help you realise how calling instance variables or instance methods will not work in a static context.
6th Sep 2019, 12:10 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Declaring a variable inside a static method does not require the keyword static. "method not static inside method static " You can't declare method direct inside method. If you mean how to call non-static field you must create object first. public class Program { int nonStatic; public static void main(String[] args) { //static method new Program().main2();} void main2(){ nonStatic=20; //non static method nonStatic(); } void nonStatic() { } }
6th Sep 2019, 1:21 AM
zemiak