I'm still learning C # and just asked the main question about inheritance.
Let's say I have an abstract class SportsPlayer:
public abstract class SportsPlayer
{
string name;
int age;
Sexs gender;
public SportsPlayer(string n, int a, Sexs g)
{
this.name = n;
this.age = a;
this.gender = g;
}
}
And a subclass called SoccerPlayer:
public class SoccerPlayer : SportsPlayer
{
Positions position;
public SoccerPlayer(string n, int a, Sexs g, Positions p)
: base(n, a, g)
{
this.position = p;
}
public SoccerPlayer()
{
}
Is it possible to create a constructor in a subclass that did not pass any arguments, or am I right in thinking that in order to create a default constructor in a subclass, a superclass must have a default constructor?
Also, if I were to add a default constructor to the superclass, how would I initialize the superclass variables in the subclass constructor? In java it super(), in c # it?
public SoccerPlayer():base()
{
base.name = "";
}
???
source
share