Can we override main() method?

class A
{
public static void main(String[] args)
{
System.out.println("parent class main() method");
}
}
class MainMethod5 extends A
{
public static void main(String[] args)
{
System.out.println("child class main() method");
}
}
/*
Output:- parent main() method
Explanation:- It seems overriding concept applicable for main() method but it is not method overriding,
it is method overhiding. If we execute class A,then A class main() method will be executed
and if we execute MainMethod5 class main() method then it will execute its main() method.

*/

0 comments: