Q:

In java, a composite object cannot contain other objects. what does it means?

I am confused with the following statement . Could anyone help me in understanding the following statement?

In java , a composite object cannot contain other objects. It can only have references to its constituent objects. Constituent Objects can be shared between objects and their lifetime can be independent of the lifetime of the composite object.

A:

In other languages, such as C++, an Object can be thought of as containing another object.  If an object of class A contains an object of class B, A will be bigger than B.
In Java you only have references from one class to another (a part from inheritance) If A references B, it doesn't matter how big B is, it doesn't influence the size of A.

A:

It means that in Java, unlike in languages such as C++, an object cannot contain other objects, only references to them.
This means that there is no practical difference between the concepts of composition and aggregation. In a composite an object's lifespan is confined within the lifespan of the containing object and typically the containing object creates the contained one. In an aggregate there's more freedom.

A:

Consider something like this:
class Foo {
}

class Bar {
    Foo my_foo = new Foo();
}

my_foo is a reference to a Foo object, it's not the object itself.  The Foo object itself is not directly tied to the "enclosing" Bar object.

