Hi guys,
So I'm wondering why cant I reference a value or even access a value that's in a method from another method.. like so
public class Main {
public static void main(String arg[])
{
String bob = "bobby";
compute();
}
public static void compute()
{
main.bob = "yoyo";
}
}
I don't know if I'd ever want to do this, but I'm just curious, does this mean that there's simply no other way to modify the variable values of a method without providing it with values through invoking the method ?
So in the following way I can basically set what values (true to the predefined data types) these argument variables will have..
public class Main {
public static void main(String arg[])
{
String one = "Ping",two = "Pong";
String Result = "";
Result = compute( one, two);
System.out.println(Result);
}
public static String compute(String first, String second)
{
String joined = first + " " + second;
return (joined);
}
}
What if instead of this I have
String joined = first + " " + second;
String joined_2 = third + " " + forth;
String Altogether = joined + joined_2;
return (Altogether);
So say i get to the first line in that code and suddenly want to change a value in the second line, would that be possible ?
Okay crappy example, I suppose parameters are then the only manner available for methods to get values from the invoking method ?
↧