Hi guys. I have a couple of questions from an official practice exam I did tonight. Here they are:
1) We all know that static variables are not serialized. When serializing and deserializing an object
in the same execution, the static variables don't change their values, isn't it?
The answer implied that they were reset to their initial declaration value, and I'm starting to think it was an errata.
2) Another answer claimed that a composition scheme where a Class A holds a reference to an instance of another Class B, and at the same time class B has an instance of class A, is tight coupling. Reading from chapter 2 in K&B's book, it is said:
Tight coupling is the undesirable state of having classes that break the rules of loose coupling.
So if we read those rules, they say:
Loose coupling is the desirable state of having classes that are well encapsulated, minimize references to each other, and limit the breadth of API usage.
In the question, classes A and B were well encapsulated (private references, only setters with package-default access modifier), and no method calls over the instances were made (and of course no inner variables were accesed from outside the class). Why are then considered tigthly coupled? Should I consider tight coupling every composition (has-a relationship) where references are not interfaces? Or even with interfaces it is considered tight coupling? Do you have a rule of thumb for this kind of question?
Thanks.