Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Why do we mark main method as static in Java?

Pragya Keshap answered on February 4, 2023 Popularity 5/10 Helpfulness 1/10

Contents


More Related Answers

  • java main
  • static mode java
  • main method in java without static keyword
  • what is main method in java
  • java define main function
  • main methode java
  • why main method static
  • why main method is public static void in java
  • main in java
  • java main method
  • java main
  • java main
  • what is the use of static blocks in java
  • main method
  • what does static mean java
  • what is use of static block in java
  • main method in java
  • why we use static in java
  • the main of java
  • What is the use of the “static” keyword in Java?
  • do i have to use static methods in java main
  • how to call a static method in java
  • why is the main method static in java
  • Static Method in Java
  • static method in non static class java
  • what is a static variable in java
  • Calling Static Method in Java
  • Is the main method compulsory in Java?
  • how to call the main method in java
  • What is a Static Method? Why do we need Static methods in Java 8 Interfaces?

  • Why do we mark main method as static in Java?

    0

    The main method in Java is marked as static, so that JVM can call it to start the program. 

    If main method is not static, then which constructor will be called by Java process?

    As such it is a known as convention to mark main method static in Java.

     But if we remove the static, then there will be ambiguity. 

    Java process may not know which method of a class to call to start the program.

    So this convention helps in Java process to identify the starting code for a program in class that is passed as an argument to java process.

    https://www.tutorialspoint.com/why-the-main-method-in-java-is-always-static#:~:text=Java%20main()%20method%20is,where%20compiler%20starts%20program%20execution.

    Popularity 5/10 Helpfulness 1/10 Language java
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 04 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.