0
public class Sample{
     public static void main(String args[]){
    System.out.println("/n Say hi 2 me");
        }

public class Hello{
      public static void main(String args[]){
    System.out.println("/n Hello!");
         }
      }
   }

I have run this code using Command Prompt but I was able to notice that modifier 'static' is used for only constant variable Declarations why????? please help me out in understanding this???

2 Answers2

0
public static void main(String[] args)

main method with single String[] (or) String... as param will be considered as entry point for the program.

So we cant have two completely same main methods in one java class

you can have other method named main but it should have different parameters(overloading of method)

kirti
  • 4,499
  • 4
  • 31
  • 60
0

static can be used with variables as well as methods but can't be used for a class static variables are initialized before the object creation when the class is loaded and static
methods can be called before object creation as well

Yusuf Kapasi
  • 577
  • 2
  • 9