Yes , overloading of main function is allowed in java. We can overload main method for better demonstration consider the following example.
The above program is show the following output.
OUTPUT:
Main
Int main
But overriding of main method is not allowed because of static type of main method. The static method is class level method not Object level method that is why we can't override main method.If we doing this this is not overriding but method hiding.The following program show better demonstration of this concept.
The output of the program is as follows:
OUTPUT:
child
Parent
Parent
No comments:
Post a Comment