Can u overload main()method.Give with example.

Answers were Sorted based on User's Feedback



Can u overload main()method.Give with example...

Answer / aditya sharma

* Yes we can overload the main method.

File Name :- checkOverloadingMainMethod.java
Example: -

public class checkOverloadingMainMethod {

public static void main(int a[]) {
System.out.println("Overload =>Integer Array");
}

public static void main(String args[]) {
System.out.println("Overload => String Array");
}
}

Is This Answer Correct ?    120 Yes 18 No

Can u overload main()method.Give with example...

Answer / rama krishna dwadasi

Yes, We can overloaded main method also,,,,but JVM start
execution from main method with parameters of String args[]
only...so below example output is "Inside second method"

Example:

public class OverloadMain {

public static void main(int a[]) {
System.out.println("Inside first Main Method");
}

public static void main(String args[]) {
System.out.println("Inside Second Method");
}

}

Is This Answer Correct ?    51 Yes 5 No

Can u overload main()method.Give with example...

Answer / manikandan [ gtec,vellore ].

yes,gothrough below code.

class test
{
public static void main(String []asdff)
{

test.a();

}
public static void main(int a,int b)
{
System.out.println("over loaded");
}
static void a()
{

test.main(1,2);
}
}

Is This Answer Correct ?    40 Yes 12 No

Can u overload main()method.Give with example...

Answer / tushar

class Checkmain
{

public static void main(String args[])
{
System.out.println("helloCheckmain string main ");
}
}

class Checkmain1 extends Checkmain
{
public static void main(String args[])
{
System.out.println("helloCheckmain1 string main ");
}
}

public class Main
{
public static void main(String args[])
{
String S[]=new String[10] ;
System.out.println("******string main**********");
int q=10;
main(q);
Checkmain.main(S);
Checkmain1.main(S);
}

public static void main(int a
{
String S[]=new String[10] ;
System.out.println("000000000 int main 0000000000");
Checkmain.main(S);
Checkmain1.main(S);
}
}

Is This Answer Correct ?    8 Yes 1 No

Can u overload main()method.Give with example...

Answer / kuldeep

yes it is possible in java but jvm call only one main()
method. for eg.

class test
{
public static void main(String []ar)
{
System.out.println("his is 1 st main() method");
}

public static void main(String ar[],String []st)
{
System.out.print("overloaded main() method");
}
}

but o/p of this program is: 1st main() method statement is
display. but why its ans. is at complile time String ar
argument contain one argument it is class name for making a
class file or byte code file. 2 arg store the one class
name it is not possible

Is This Answer Correct ?    9 Yes 3 No

Can u overload main()method.Give with example...

Answer / srinu

yes we can overloaded the main() method

public class A
{
public static void main(int a[])
{
System.out.println("overloaded method");
}

public static void main(String a[])
{
System.out.println("main method");
}


output: overloaded method

Is This Answer Correct ?    26 Yes 89 No

Post New Answer

More Core Java Interview Questions

What one should take care of, while serializing the object?

0 Answers  


What is a line break?

0 Answers  


What is UNICODE?

3 Answers  


Can you declare an interface method static?

0 Answers  


Can we force the garbage collection to run?

0 Answers  






what is nested class in java?

0 Answers   IBS,


After compilation of java program we'll get .class code. If it's generated in OS Windows XP will it work on OS Linux? If yes why? If no why?

5 Answers   Aricent,


There are 2 classes, 1 LandAnimal and another WaterAnimal. There is another class Animal which wants to have the properties of both LandAnimal and WaterAnimal. How will you design this situation?

6 Answers   KPIT,


How does marker interface provides functionality to the implemented class ? or How dose maker interface gets the functionalities as serialization or cloning.

4 Answers   Cap Gemini,


What are the disadvantages of using inner classes?

0 Answers  


What is the purpose of the System class?

0 Answers  


Why we use methods in java?

0 Answers  


Categories