Greetings,
I'm a little bit confused about method returns, I know how to set a method to return a value, but how is that value then accessed by the class/method that called it?
cheers
Printable View
Greetings,
I'm a little bit confused about method returns, I know how to set a method to return a value, but how is that value then accessed by the class/method that called it?
cheers
let consider a program
class Second{
String newMethod(){
return "this is how the value returned";
}
}
class First{
public static void main(String a[]){
Second e=new Second();
System.out.println("returned value - "+e.newMethod());
}
}
after creating the object for Second class the jvm go to execute print statement.
it prints the first string and then immediately we call the method newMethod() so it go to that method, inside that method we returned some value that value is stored in object e. the value in object e displayed on console.
Hope you understand.
Returning a Value from a Method (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
and the rest of that tutorial trail.
db
cheers akiravelmont, that helped a lot
@Darryl.Burke, that didn't, I had already read that tutorial
most welcome. if you have any queries message me. i will help you:):)