Problem 226

Dog Constructor

It is time we start to complicate the creation of classes.

Think about creating an instance of an object. And then assigning values to its fields.

Student student = new Student();
student.firstName = "Frank";
student.lastName = "Smith";
student.birthYear = 1988;

Required files:

  1. Create a constructor for the Dog class. Compile it.
  2. Compile and Run DogRunner and ensure the output is as below.

What you should see

Woof
Woof
Ralph is 28 dog-years old
Fido is 42 dog-years old
Fido is 14 dog-years older than Ralph

◄ 225: Constructors 227: Encapsulation ►