The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details. |
Home Iteration More Encapsulation | ||
See also: Encapsulation | ||
Search the VIAS Library | Index | ||
More Encapsulation
To demonstrate encapsulation again, I'll take the code from the previous section and wrap it up in a method: int i = 1; while (i <= 6) { printMultiples (i); i = i + 1; } } The process I am demonstrating is a common development plan. You develop code gradually by adding lines to main or someplace else, and then when you get it working, you extract it and wrap it up in a method. The reason this is useful is that you sometimes don't know when you start writing exactly how to divide the program into methods. This approach lets you design as you go along.
|
||
Home Iteration More Encapsulation |