How do you use a object, returned by a method, to call a method of a different class?
just a simple example will do.
Thanks,
Mandrake
Printable View
How do you use a object, returned by a method, to call a method of a different class?
just a simple example will do.
Thanks,
Mandrake
Code:public class ClassExperiment {
static AnotherClass anotherClass = new AnotherClass();
public static void main(String[] args) {
AnotherClass ac = getReference();
String s = ac.someMethod();
System.out.println("s = " + s);
}
private static AnotherClass getReference() {
return anotherClass;
}
}
class AnotherClass {
public String someMethod() {
return "someMethod of " + this;
}
public String toString() {
return getClass().getName();
}
}