InterviewSolution
| 1. |
A Java program begins with a call to which function? |
|
Answer» When a JAVA program begins, the public static void main(String []args) method is called. When the Java program needs to be executed, the system looks for the main entry point in the program. This is provided through the main method, The public static void main(String args[]) is the main method of the Java Program. It is the most important Java Method. It is the entry point of any Java Program. A Java Program cannot be executed without the main method. Only the args can be changed to a different name but the rest of the method carries the same syntax. Let us analyze the main method by breaking it up:
The following program will illustrate that the main method is run at first: public class Example { void display() { System.out.println("This is the display method"); } public static void main(String[] args) // the main method { System.out.println("This is the main method"); Example obj = new Example(); obj.display(); // invokes display method } }The output is as follows: $javac Example.java $java Example This is the main method This is the display method |
|