M
M
Michaelis2016-01-30 15:03:48
Java
Michaelis, 2016-01-30 15:03:48

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

2 answer(s)
O
Oleg Gamega, 2016-01-30
@Michaelis

object.object.method();

the object has a public field the object on which you call the method
there is a public method that returns some object on which you call the method

T
twobomb, 2016-01-31
@twobomb

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();

Hello
Hello

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question