প্রশ্ন : আমরা কি জাভা main method কে overload করতে পারি ?


উত্তর : হ্যা পারি । আমরা জাভা method overloading ব্যাবহার করে class এর মধ্যে অনেক গুলা main method লিখতে পারি ।
কিন্তু জাভা ভার্চুয়াল মেশিন (JVM) সেই main method টাকে ই call করে যার আর্গুমেন্ট হিসেবে স্ট্রিং টাইপের এরে থাকে । তো চলুন দেরি  না  করে  আমরা একটি ছোট উদাহরণ দেখি main method overloading এর -


   public class MainMethodOverLoadding {
public static void main(String[] args) {
System.out.println("Main Method Called Which is with String array");
}
public static void main(String args) {
System.out.println("Hello World - string type");
}
public static void main(int args) {
System.out.println("Integer Type");
}
public static void main() {
System.out.println("No argument ");
}

}

/**
 * Note :You can have any number of main methods in a class by method overloading.
But JVM calls main() method which receives string array as arguments only.
 * 
 */

মন্তব্যসমূহ

Popular Posts

Simple 2D hut design in computer graphics using c++

HashMap in Java