Hey Guys Do You Have This Code I'm Stuck? Lol :D

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.

A class constructor will allow us to create Dog instances. With a class constructor, we can set some information about the Dog.
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.
Add a class constructor called Dog to the class.

Note: If you’re getting an error in the console about a main method, include the following code within the Dog class (it will be explained later in this lesson):

Yes, we have. Do you want us to help you? Post your code and describe your problem.

A post was split to a new topic: Hey I got Stuck on Constructor exercise can you please help me out?

I’m sorry about taking so long to reply but I don’t know what code to put in. I tried this. . .

the problem asks me to add a constructor called dog to the class and I did not know what to do lol.

So I Tried doing this

Class Dog {

//The class constructor for the Dog class
public Dog() {

public static void main(String args) {

But that did not work I was wondering if you could give me the code please I’m on Learn Java and Dog.Java Classes Constructor

Your code is pretty good. You just need to remember that keyword class should be lowercase and that you have to close method definitions using }:

class Dog {

  //The class constructor for the Dog class
  public Dog() {


  public static void main(String[] args) {

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.