indra kumar kothare
Is it possible to have two Main() in the class ?
By indra kumar kothare in .NET on May 16 2016
  • Madan Shekar
    Nov, 2018 5

    Yes it is possible to have two main() in the same program. For instance, if I have a class Demo1 as below. ... Yes, you can have as many main methods as you like. You can have main methods with different signatures from main(String[]) which is called overloading, and the JVM will ignore those main methods.Nov 15, 2012class Sum {int add(int a, int b) {return (a+b); }public static void main (String args[]) {System.out.println(" using Sum class");Sum a = new Sum();System.out.println("Sum is :" + a.add(5, 10));}public static void main (int i) {System.out.println(" Using Sum class main function with integer argument");Sum a = new Sum();System.out.println("Sum is :" + a.add(20, 10));} }class DefClass {public static void main (String args[]) {System.out.println(" using DefClass");Sum a = new Sum();System.out.println("Sum is :" + a.add(5, 10));Sum.main(null);Sum.main(1);} }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS