I assume the question is about Java.
How you call a method from inside the main method depends on whether this is an instance method or a static method.
To call an instance method, you need to have a valid instance.
Say foo is an instance of class Foo, which was created inside the main method.
Then to call the instance method implode() use
foo.implode()
To call the static method bar() of class Foo, use
Foo.bar().
No
At the time of developing jvm the development team by default make a only one method call i.e; 'main' method call in the jvm that's why when the call is loading into the jvm the jvm call the main method...and execution was starts..
We can't call a class. We always call a method in java.
Main method in java is always static as main method id the only method from where the program execution starts,and as we all know that main method is defined inside a class so JVM needs to make a object of the class to call the method and objects are build inside the main method ,so to execute the main method it has to make objects of the class but objects are build inside main method so that's the reason that main method is static so that JVM can execute the main method without making its object as static members can be called by class anme only
Declaring a method is when you code for what the method will perform. When you call a method, you are using the method you have written in another part of the program, (or inside the method if it is recursive).
No, the reason is simple: A method marked as a static means, that you don't need create an instance (create an object with the 'new' operator) in order to use it. The main method is the entry point for a java application, therefor there is nothing after you call it. no one who can create an object of the type of your class and call the main method. So the jvm must call the main method with no object reference.
Yes you can. Try this: public class TestMain { /** * @param args */ public static final void main(String[] args) { System.out.println("Inside final mail method..."); } } It will print "Inside final mail method..." in the console.
The main method is static because the JVM would be invoking this method as the starting point of execution. If this is like other normal methods, the JVM would have to instantiate an object of the class before it can call it. This is not possible because this is the starting point. If the main method is static the JVM can directly call this by specifying the class name.
we can call global variables in main method by using scope resolution operator(::) if local and global have same name for example int x=10; main() { int x=20; cout<<x; //x=20 cout<<::x; //x=10 }
No. There can only be one main method, however you can declare new methods, and call them from the main method. Or you can use multi-threading, to simulate having multiple main methods.
Because, the main method is the starting point of the java program and if we need an object of that class even before the main can be invoked, it is not possible. Hence it is declared static so that the JVM Can acess the main method without having to instantiate that particular class
It doesn't really make sense. The JVM needs to know where to start running the program; that's what the "main" method is for. A class - one that can be run directly - needs to have a single entry point, to avoid ambiguity. This main method can then call any number of other methods. I assume you can call a second method "main", but using a different signature. However, to avoid confusion, I would recommend you don't do this.