Interview Questions and Answers for 'Sapientnitro' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Sapientnitro' - 2 question(s) found - Order By Newest

 Q1. Can we have multiple main methods in a single class ?Core Java
Ans. We can overload the main method by specifying different argument types. For example -

2 main methods with different arguments is perfectly legal

public static void main();
public static void main(String[] args);

The following are not legal as compiler will complain of duplicate methods

public static void main(String[] args);
public static void main(String[] args);

Even The following are not legal as we cannot overload on return types

public static String main(String[] args);
public static void main(String[] args);

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     main method     Asked in 2 Companies


Related Questions

  Why do we write public static void main ? Can we use some other syntax too for main ?
 Which of the following is false about main method ?

a. It should be declared public and static
b. it should have only 1 argument of type String array
c. We can override main method
d. We can overload main method
  Can we overload main method in Java ?
  What will happen if static modifier is removed from the signature of the main method?
  How can we execute a Java class independently if it doesn't have a static main method ?
 Can we declare a main method as abstract ?
 Do all java classes need a main method?
 Can we declare the main method as private ?
 Why main method is declared static ?


 Q2. Can an application have multiple main methods within different classes ? If yes, How will the app decide which one to be executed ?Core Java
Ans. Yes we can have a main method with string[] argument in every class of an application. When we execute an app we specify the starting point i.e the class that will get the control first and hence main method of that class gets executed.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     main method     Asked in 3 Companies


Related Questions

  Why do we write public static void main ? Can we use some other syntax too for main ?
 Which of the following is false about main method ?

a. It should be declared public and static
b. it should have only 1 argument of type String array
c. We can override main method
d. We can overload main method
 Can we have multiple main methods in a single class ?
  Can we overload main method in Java ?
  What will happen if static modifier is removed from the signature of the main method?
  How can we execute a Java class independently if it doesn't have a static main method ?
 Can we declare a main method as abstract ?
 Do all java classes need a main method?
 Can we declare the main method as private ?
 Why main method is declared static ?



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: