How would I go about doing this in java?
I need the constructor in my subclass to call the inherited constructor in my superclass. is there a special syntax that i need to use in order to do this?
I've used extends to inherit from the Person class. How would i go about using super()?
Here is my class:
public class Student extends Person
{
protected int id;
public Student()
{
// how do i call the inherited constructor here?
}
}
Exactly like that:
super()
. But I assume you need to call a method with arguments since there's an implicit call tosuper()
. Add arguments, like this:super(arg0, arg1, arg2, etc);
.super(arg1, arg2, etc);
There's an implicit call to
super()
(with no arguments) at the beginning of any constructor that doesn't call it explicitly.