Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Main method in java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 208
    Comment on it

    Hello guys

    Here, I am simplifying the java main method, In which beginners have many confusions about public, static, void and String array.

    First of all see below simple java example :

    package bhagwan;
    
    public class Findnerd
    { 
            public static void main(String [] args)
            {
                    System.out.println(Java simple example);
            }
    
    }
    



    Now, to resolve your confusion's or question's about java main method are below.

    Q.1 Why is java main method public?

    Ans. Java main method is invoke by the JVM, so we need to mark as public to main method.



    Q.2 Why is java main method static?

    Ans. Java virtual Machine(JVM) can call it without creating any instance of class which contains main method and JVM is also static.

    Q.3 Why is java main method void?

    Ans. Java main method return void, so we need to define return type with void. But we can write "return" statement as below :

    package bhagwan;
    
    public class Findnerd
    { 
            public static void main(String [] args)
            {
                    System.out.println(Java simple example);
              return;
            }
    
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: