Question: In java all methods are pass by value.But today i learnt that constructors are pass by reference.

```
// Attack the internals of a Period instance
Date start = new Date();
Date end = new Date();
Period p = new Period(start, end);
end.setYear(78);  // Modifies internals of p!

```

This works and is able to edit the private fields.

What is the reason of this decision? or am i missing something?

Answer: 
It will work same way for other method. Actually reference is passed by value.

```
Class A{
   B b;
   void setB(B b) {
       this.b = b;
   }
};

A a;
B b;
A.setB(b);

b.change(); //changed in A

```

What it means that reference is passed by value?

```
void f(A a) {
    a.change(); // caller will see that object is changed. We change it using reference
    a = new A(); // we change the value of refernce. No changes are visible outside the function
    a.change(); //new object is changing. No changes are visible outside the function
}

```

Basically you just pass address of object (integer) by value. Everything is integer. Your class contains integer. And it didn't change. The objects on that address did.
No, you aren't changing any private fields. The private fields in Period are not touched, they still reference the same object. Unfortunatly, a Date object is mutable. So you see the mutation through the Period object.

If you want to avoid this, make a copy of each object passed in the constructor, only thus you'll have your own Date objects no one outside of Period can modify.