If I have a superclass Animal
with no attributes, and then another subclass Dog
with one attribute, is it valid to use the super()
method when creating the constructor for the subclass? Here's the example code:
public class Animal {
public Animal() { }
}
public class Dog extends Animal {
public int age;
public Dog(int age){
super(); // Do I include this?
this.age = age;
}
}
Is there any reason why I should or should not call the super()
function in the Dog
class, and does it make a difference? Thanks!