Say I have the Class Sheep and the 2 parameters 'speed' and 'rotation'. Speed is optional, rotation is not. How do I use Constructor Overloading to avoid nulling? I can't really get it to work.
public class Sheep extends Actor
{
private int speed,rot;
public Sheep(int rotation)
{
rot = rotation;
speed = 0 //default value
}
public Sheep(int rotation,int sheepSpeed)
{
this(rotation);
speed = sheepSpeed;
}
}public Sheep()
{
this(0, 0);
}
public Sheep(int rotation)
{
this(rotation, 0);
}
public Sheep(int rotation, int sheepSpeed)
{
rot = rotation;
speed = sheepSpeed;
}
import greenfoot.*;
public class Sheep extends Actor
{
private int speed,rot;
public Sheep(int rotation)
{
rot = rotation;
}
public Sheep(int rotation,int sheepSpeed)
{
this(rotation);
speed = sheepSpeed;
}
}