Since each object has data that only belongs to itself, we don't have to worry about changing the position of Ball A and it somehow interfering with the position of Ball B. Encapsulation prevents your program from modifying the wrong information. From a security and memory management perspective, this is essential.println() method from the System.out object prints a message to the screen. You don't have to fully understand the inner workings of the system output stream to use () - all you need to understand is the. We just pop (import) them into our programs and they more or less magically start working. without having to directly access or modify their data. This is why we can use Scanners, ArrayLists, BigDecimals, etc.When data is attached to a certain object we say that it's encapsulated.The program can use a Ball object without having to know the actual implementation of the object. bounce() method, without having to directly access the internal code making up a Ball object. The program might be able to trigger the Ball's movement using its public. Ball A can have a radius independent of Ball B. Each Ball created is then its own separate entity. We can also create a bounce method that affects the position of the ball. We can create a "Ball" object and say it has a radius and a position. Encapsulation refers to objects having their own private state and functions, which are only accessible via public functions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |