Introduction To Object-Oriented Programming


Class UML for the 3 classes and 1 interface defined
in the Inheritence section of this tutorial.

As an object oriented language, Java relies on the principle of objects. Objects are simply just data, and a collection of methods that manipulate that data, so for example the Animal class can have a .rest() method. The two most important principle of object orientation are encapsulation, and inheritance.


Encapsulation

At its core encapsulation is the hiding of implementation details from of a class and its clients. Client classes should only interact with a class through well documented methods. To accomplish this task java has access modifiers that allow the writer of the class to set the access level of all fields, and methods of a class. Java has 4 access modifiers (in order from most to least private): private, protected, default and public. public and private are the most commonly used, public means everyone has access to it, and private means only classes of the same type can access the member. Consider the following class: