class A{
String z(){
System.out.println(\"a\");
return \"sauarbh\";
}
}
class B{
A a;
A x(){
return a;
}
}
public class runner
To call:
String z(){
System.out.println("a");
return "sauarbh";
}
without the object of the class A
the method z
has to be static:
static String z(){
System.out.println("a");
return "sauarbh";
}
So change your code as following:
class A{
static String z(){
System.out.println("a");
return "sauarbh";
}
}
class B{
A a;
A x(){
return a;
}
}
public class runner {
public static void main(String[] args) {
B b = new B();
b.x();
A.z();
}
}
Output :
a