Originally posted by Ashok Pradhan: This Question is from MasterExam:-
Which istantiation creates the tightest coupling?
A BioDiesel b1 = new BioDiesel();
B BioDiesel b2 = new BioDiesel(new String("canola"));
C BioDiesel b3 = new BioDiesel(new Integer(42));
D BioDiesel b4 = new BioDiesel(new Viscosity());
The answer is D ,but someone can explain me why it is D.Thanks..
Coupling means high Dependency on some other class. So when the other class is changed, this class is affected drastically.
in option 1, the class has no dependency on any other class
in option 2, class depends on String class, which is final. So the class definition will be constant.
in option 3, class depends on Integer class, which also is final.
in option 4, class depends on a class called Viscosity, which is developed by some other user. So there are very high chances that if Viscosity class is changed,the Biodiesel class will be affected drastically.