Object Oriented Java


#1


<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.
Instructions
1.
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):

public static void main(String[] args) {

}
Report a Bug

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/classes-constructors?action=lesson_resume&link_content_target=interstitial_lesson

I am trying to get the code set right, but I am not understanding the objective of this part of the lesson.


class Dog {




	public static void main(String[] args) {

	}

}

https://www.codecademy.com/courses/learn-java/lessons/object-oriented-programming/exercises/classes-constructors?action=lesson_resume&link_content_target=interstitial_lesson


#2

You need to define a constructor for your class. The constructor is like a method that has two characteristics:
1. it has no return type
2. it has the same name as the class.
As you can see in the given example, the constructor for the class Car is written public Car(){}
Do the same for the class Dog


#3

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