There is one class Car and another one called Tyre. Now , with the destruction of the Car object we want its associated tyre(s) to be destructed with it. Consider the following code
class Car {
Tyre t ;
Car( Tyre t1 ) { t = t1; }
}
class Tyre {
}
class
Test {
Tyre t = new Tyre();
Car a = new Car(t);
...
...
...
...
a = null ; // I have destroyed the Car Object , but i can still refer the tyre object through t reference.
}
Problem : - I want to do something so that i can enforce this thing that whenever i make car reference equal to null then there is no way to access tyre(s) associated with it.
How would i achieve this or enforce this ???