Hi,
In java and c++, the main function comes out side the class but in C# the main function comes inside class. why?
Plz, Help me
Thanks.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Sep 26, 2011, 4:09 AM
Similarly, in C# the Main() method must be inside a class or struct (Java doesn't have structs).
This is because Java and C# are pure object oriented languages which don't support global functions.
However, because of its C heritage, C++ supports procedural as well as object oriented programming. Consequently it does support global functions and the main() function must in fact be defined as a global function - it can't be defined as a member function of a class.
Prabhu RajaPosted Sep 26, 2011, 1:49 AM
Example:
class Sample {
public static void main(String[] args) {
System.out.println("Java rules the world!");
}
}
the Above Class will Execute with out any problem.
If one Class is a Resource for another classes , that class may or may not have main method inside.
-------------------------------------------------------------
If this post helps you, then mark as "Correct Answer"
Thank You
Lalit MPosted Sep 26, 2011, 12:58 AM