Both C++ and Java differentiate between methods by the number and type of arguments they receive.
So you can have overloaded methods like
public static void main(int myInteger) { }
public int main(int myInteger) { return 0; }
Note: These methods will not be the entry point of your program unless they meet certain rules.
For java it has to be:
public static void main(String[] args) { }
For c++ it has to be:
sometype main(int argc, const char* argv[]) { }
How to overload main() In JAva And C++?
Just write it; i'm assuming you are referring to methods/functions their requirement is being methods of different cardinality/# of parameters and/or different parameter types.
C++ also have operator overloading that translate to the function name of 'operator*' but Java doesn't have it.
Reply:If you talking about "static void main in Java" or "int main() C++" There's no way to overload main function (method) in C++ or Java. main method is the entry point of the program. When it's translated to Assembly, it always has the main routine. (Long time i have not touched Assembly, some of the terminology i used could be wrong but the basic idea is something like that)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment