class MyClass { //field, constructor, and method declarations }
The preceding class declaration is a minimal oneit contains only those components of a class declaration that are required. You can provide more information about the class, such as the name of its superclass, whether it implements any interfaces, and so on, at the start of the class declaration. For example,
class MyClass extends MySuperClass implements YourInterface { //field, constructor, and method declarations }
means that MyClass
is a subclass of MySuperClass
and that it implements the YourInterface
interface.
You can also add modifiers like public or private at the very beginning—so you can
see that the opening line of a class declaration can become quite complicated.
The modifiers public and private, which determine what other classes can access MyClass
,
are discussed later in this
lesson.
The lesson
on interfaces and inheritance
will explain how and why you would use the extends and implements keywords in a class declaration.
For the moment you do not need to worry about these extra complications.
In general, class declarations can include these components, in order: