Can we override the main method?

Answer Posted / sadikhasan palsaniya

Yes we can override main method that explain by following Code.

public class DemoOverride {
public static void main(String string[]){
System.out.println("I am in Main method of super class");
String str[]={"sadik","palsnaiya"};
Over1.main(str);
Over2.main(str);
}
}


class Over1 extends DemoOverride{
public static void main(String str[]){
System.out.println("I am in Main method of Middle
class");
}
}

class Over2 extends Over1{
public static void main(String str[]){
System.out.println("I am in Main method of Child class");
}
}

Is This Answer Correct ?    8 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Give me some null interfaces in java?

603


What are the object and class classes used for?

557


What is nested loop? What is dangling else condition in it?

574


What is the purpose of static keyword in java?

517


make a method which any number and any type of argument and print sum of that arguments.....

1382






Can abstract class have private constructor?

496


How many bits is a string in java?

577


Why java is considered as platform independent?

591


Can we declare a class as static?

593


What is the reason behind using constructors and destructors?

558


What is map and hashmap in java?

620


What is percentage in java?

573


Why object class is super class for every class in java?

569


Is arraylist ordered?

563


Explain public static void main(string args[]).

569