+ 1

Can someone explain method return type?

please

29th Sep 2017, 3:49 AM
Abinesh N
Abinesh N - avatar
5 Answers
+ 1
It looks like you are trying to declare a function in the middle of another one, but forgot the name and argument type. You get a compile error on static because it can't be used in the middle of main. I'm thinking you want something like: class Program { static String x(String name){ if(name.equals("david billa")){ return name; } else{ return "dghj"; } public static void main(String[ ] args) { String name =("david billa"); System .out.println(x(name)); } }
29th Sep 2017, 4:54 AM
John Wells
John Wells - avatar
+ 1
class Program { public static void main(String[ ] args) { String name =("david billa"); System .out.println(name); static String (name){ if(name.equals("david billa")){ return name; } else{ System.out.println ("dghj"); } } }
29th Sep 2017, 4:05 AM
Abinesh N
Abinesh N - avatar
+ 1
whats wrong in the above program
29th Sep 2017, 4:05 AM
Abinesh N
Abinesh N - avatar
+ 1
return 0; // ending the program(no error) return 1; //indicate some error The value returned fromĀ main()Ā is returned to theĀ shell that called the program. Generally, the return values convert to the boolean values ā€˜falseā€™ for 0 and ā€˜trueā€™ for 1 non-0 values in a context where a conversion to boolean happens, for example, if your function call is within an ā€˜ifā€™ condition, `if(myFunction())ā€¦`, here if myFunction() returns 0, the statements inside the if wonā€™t get executed.
29th Sep 2017, 5:19 AM
Anuj kumar
Anuj kumar - avatar
0
int myMethod() {return 5;} The return type of this method is int. You declare it in the beginning and what you return has to be of that type.
29th Sep 2017, 4:01 AM
1of3
1of3 - avatar