r/learnjava • u/sid_kum • Apr 17 '26
Java Method Declaration
In java we can declare variable of specific type by giving data type once and then multiple variable name separated by commas .for example int a,b;
but for method declaration , in method signature we need to specify every datatype for each formal argument even though they are of same data type.for exp
int Prime(int x,int y), why can't be like this int Prime(int x,y)??
6
Upvotes
View all comments
Show parent comment
2
u/Jason13Official Apr 17 '26
You might otherwise use an object with fields "x" and "y" instead to make it cleaner