One of the common doubt among Java beginners while learning overloading and overriding is, whether its possible to overload main in Java ? Can you override main method in Java? How will JVM find if you change the signature of main method as part of method overloading? etc. These are good question and shows curiosity and application of knowledge of students, so if you are tutor you must answer these questions. Short answer to, can we overload main method in Java is Yes, you can overloading, nothing stops from overloading, but JVM will always call the original main method, it will never call your overloaded main method. we will learn this in little more detail later, now coming to next question, can you override main method in Java? answer is No, because main is a static method and static method cannot be overridden in Java. In order to answer this question understanding of overloading and overriding is necessary. You should know that overloading takes place at compile time and overriding takes place at runtime. You should also be familiar with rules of method overloading and overriding in Java. Though main is a special method because its the entry point of your Java application, it follows same rule of method overriding and overloading like any other method. In this article, you will learn how to overload main method to see whether JVM calls the original, standard main with string argument or not.
Read more »
No comments:
Post a Comment