0
Also, why does the code in the examples keep appearing with the main on the bottom? Isnt it supposed to go right after class?
4 odpowiedzi
+ 3
You can put the main method anywhere inside the class. After all these are just methods and could be declared in any order. The only thing that matters is that they must be inside a class.
+ 1
Awesome!!!! That makes sense!!!! Thanks a bunch, Avinesh!!!!!
0
Im doin the java part.
I see that the second block of code has the main. I flipped both blocks and i still get the same result, and i dont have any problems with following the examples, i'm just curious if theres a "proper" way or if it doesnt matter. Like i said it prints out the same value both ways.
Thanks in advance!
class MyClass {
static int sum(int val1, int val2) {
return val1 + val2;
}
public static void main(String[ ] args) {
int x = sum(2, 5);
System.out.println(x);
}
}
//or this way
class MyClass {
public static void main(String[ ] args) {
int x = sum(2, 5);
System.out.println(x);
}
static int sum(int val1, int val2) {
return val1 + val2;
}
}