> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/java/composite.md).

# Composite

Declare reference type variable as class member.

```java
class Circle {
    //composite Point
    Point p = new Point();
    int r;
    
    Circle () {}
}

class Point {
    int x;
    int y;
}

Circle c = new Circle();
c.r = 0;
c.p.x = 1;
c.p.y = 2;

```

make small group of class, and then make class by combinatopm pf these classes.

```java
class Car {
    Engine e = new Engine();
    Door[] d = new Door[4];
    //...
}


```

How to choose relation between inherit or composite?

1. inherit : A is B.
2. composite : A has B. 90%

ex) Circle is Point. < Circle has Point.(Composit relation!)
