A constructor creates a new instance of a class, called an object. To declare one, you just need the class name (see below). When extending a class, you have to provide parameters for that class' constructor as well, e.g.:
Code:
public class Animal {
/*
* The number of legs the animal has.
*/
private int legs;
/*
* Creates the animal.
*
* @param legs The number of legs the animal has.
*/
public Animal(int legs) { // Declare a constructor for the animal class.
this.legs = legs;
}
}
public class Dog extends Animal {
/*
* The bark sound the dog makes.
*/
private String bark;
public Dog(String bark) { // Declare a constructor for the dog class.
super(4); // Provide the information to the parent class.
this.bark = bark;
}
}
Hopefully from looking at the above you can see how to complete your assignment. Reply with any questions and I'll answer them (and by the way, it's two days overdue).