Answer the question
In order to leave comments, you need to log in
How to understand type constructions in JAVA: object.object.method(); and object.method().method();?
Can you please give examples and explain these constructions?
I am learning java. I stumbled across these designs and I can not understand. After all, so far I have only seen constructions of the type: object.method();
Answer the question
In order to leave comments, you need to log in
object.object.method();
public class object1{
public object2 myobj;
object1(){
myobj = new object2();
}
public object2 getMyobj(){
return myobj;
}
}
public class object2{
object2(){}
public void sayHello(){
System.out.println("Hello");
}
}
objects1 obj;
obj.myobj.sayHello();
obj.getMyobj().sayHello();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question