Page 1 of 1

Java main method in class definition

Posted: Sat Mar 13, 2010 11:06 am
by Bullet Pulse
I'm taking a Computer Science class that uses Java, and I've learned the same types of things plus a lot more in C++ at the same time, so I often see differences between them.
So anyways, I've noticed that the main method/function has to be in a class definition in Java, whereas in C++ it doesn't/isn't.
Did they make it this way because they are trying to keep Java Object-Oriented?

Re: Java main method in class definition

Posted: Sat Mar 13, 2010 11:28 am
by MrDeathNote
Bullet Pulse wrote:I'm taking a Computer Science class that uses Java, and I've learned the same types of things plus a lot more in C++ at the same time, so I often see differences between them.
So anyways, I've noticed that the main method/function has to be in a class definition in Java, whereas in C++ it doesn't/isn't.
Did they make it this way because they are trying to keep Java Object-Oriented?
Both java and C++ are object orientated. C++ inherits the C language and C declares main in this fashion so thats probably why C++ declares main like that. I'm not sure why there's a difference it's highly possible that it was just a design desicion made by the creators of the languages.

Re: Java main method in class definition

Posted: Sat Mar 13, 2010 12:29 pm
by Bakkon
Bullet Pulse wrote:Did they make it this way because they are trying to keep Java Object-Oriented?
Typically everything in Java is seen as an object. It's the same way for C#.