I have one class named "Vessel".
I have other 2 classes named "Ferry" & "Cargo" that extend the class "Vessel".
I need to make a 4th class that has the attribute "schedule", which is an array containing every ship. Each ship must be either of type "Ferry" or "Cargo".
So is this correct?
Ferry schedule[] = new Ferry[];
Could the above array contain objects of type "Ferry" and "Cargo" ?
If not, how can I accomplish this?
Example:
class Vessel {
String name;
int length;
int year;
Vessel(String n, int l, int y) {
name = n;
length = l;
year = y;
}
}
class Ferry extends Vessel {
int passengerCount;
int carCount;
}
class Cargo extends Vessel {
int load;
}
class Port {
String portName;
Ferry schedule[] = new Ferry[];
}
↧