Classes define objects
A class is used to define the custom data structure that makes up an object of that class.
We have seen that classes are the organizational unit of a Java program. Source code for methods is always within a class, and we might expect related methods to be in the same class.
However, classes do much more than this, and are the heart of object-oriented programming in Java:
- A class is used to define the custom data structure that makes up an object.
- Classes define methods that act on those objects.
Here’s an example of creating a custom data type, Circle
, to store information about a circle:
Get hands-on with 1400+ tech skills courses.