June 2018
Beginner
722 pages
18h 47m
English
Encapsulation definitely makes it easier to achieve reusability because it hides the implementation details. For example, the getLong() method we wrote in the previous section can be reused by another method of the same class:
public long sum(int i, String s2){ return i + getLong(s2);}
It can even be made public and used by other classes, like in the following line:
int i = new Ch07DemoApp().getLong("23", "45.6");
That would be an example of a composition when some functionality is built (composed) using methods of different classes not related by inheritance. And, since it does not depend on the object state (such a method is called stateless), it can be made static:
int i = Ch07DemoApp.getLong("23", "45.6");
Well, if the method ...
Read now
Unlock full access