+ 1
Can someone explain method return type?
please
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));
}
}
+ 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");
}
}
}
+ 1
whats wrong in the above program
+ 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.
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.