Drag the edges to resize the window.

Code Editor
Object-Oriented Java

Classes: Constructors

We're off to a good start! We created a Java class, but it currently does not do anything; we need to describe the behavior of the class for it to be useful.

Let's start by creating the starting state of our class. We can do this by adding a class constructor to it.

  1. A class constructor will allow us to create Dog instances. With a class constructor, we can set some information about the Dog.
  2. If we do not create a class constructor, Java provides one that does not allow you to set initial information.

The code below demonstrates how a class constructor is created:

class Car { //The class constructor for the Car class public Car() { } }

In the example above, we created a class constructor for the Car class. This constructor will be used when we create Car instances later. The public keyword will be explained later in this course.

Report a Bug
If you see a bug or any other issue with this page, please report it here.