I am aware of the distinction between tight coupling and loose coupling, according to this articles: https://www.upgrad.com/blog/loose-coupling-vs-tight-coupling-in-java/
What I do not understand is the examples it uses.
For loose coupling, the Java code:
class Volume {
public static void main(String args[]) {
Cylinder b = new Cylinder(25, 25, 25);
System.out.println(b.getVolume());
}
}
final class Cylinder {
private int volume;
Cylinder(int length, int width, int height) {
this.volume = length * width * height;
}
public int getVolume() {
return volume;
}
}
For tight coupling, the Java code:
class Volume {
public static void main(String args[]) {
Cylinder b = new Cylinder(15, 15, 15);
System.out.println(b.volume);
}}
class Cylinder {
public int volume;
Cylinder(int length, int width, int height) {
this.volume = length * width * height; }}
Can anyone please explain how does the second code make the two classes (Volume and Cylinder) bound together (tightly coupled)? Or what makes the first code loosely coupled? Thanks.