Introduction
A Java class is a template that is used to define data types. Classes are composed of objects carrying data and methods that are used to perform operations on that data. Classes can be self-contained, extend other classes with new functionalities, or implement features from other classes. In a way, classes are categories that allow us to define what kind of data can be stored within them, as well as the ways in which that data can be handled.
Classes tell the compiler how to build a certain object during runtime. Refer to the explanation of what objects are in the Working with Objects in Java topic.
The basic structure of a class definition looks like this:
class <name> { fields; methods; }
Note
Class names should start with a capital letter, as in TheClass
, Animal
, WordCount
, or any other string that somehow expresses the main purpose of the class. If contained in a separate file, the filename containing...