public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
Plane
I am an airplane with a wingspan of 123.000000 and capacity 45
Landing gear up
Moving
Landing gear down
10.0
Car
I'm a sedan
Moving
10.0
public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
Plane
I am an airplane with a wingspan of 123.000000 and capacity 45
Landing gear up
Moving
Landing gear down
10.0
Car
I'm a sedan
Moving
10.0
public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
Plane
I am an airplane with a wingspan of 123.000000 and capacity 45
Landing gear up
Moving
Landing gear down
10.0
Car
I'm a sedan
Moving
10.0
public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
Plane
I am an airplane with a wingspan of 123.000000 and capacity 45
Landing gear up
Moving
Landing gear down
10.0
Car
I'm a sedan
Moving
10.0
public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
Plane
I am an airplane with a wingspan of 123.000000 and capacity 45
Landing gear up
Moving
Landing gear down
10.0
Car
I'm a sedan
Moving
10.0
public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
Plane
I am an airplane with a wingspan of 123.000000 and capacity 45
Landing gear up
Moving
Landing gear down
10.0
Car
I'm a sedan
Moving
10.0
public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
Plane
I am an airplane with a wingspan of 123.000000 and capacity 45
Landing gear up
Moving
Landing gear down
10.0
Car
I'm a sedan
Moving
10.0
public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
Plane
I am an airplane with a wingspan of 123.000000 and capacity 45
Landing gear up
Moving
Landing gear down
10.0
Car
I'm a sedan
Moving
10.0
public class Main{
public static void main(String[] args){
Vehicle plane = new Airplane("Plane", 123, 45);
System.out.println(plane.getName());
System.out.println(plane.describe());
System.out.println(plane.move(10));
Vehicle car = new Car("Car", 4);
System.out.println(car.getName());
System.out.println(car.describe());
System.out.println(car.move(10));
}
}
Plane
I am an airplane with a wingspan of 123.000000 and capacity 45
Landing gear up
Moving
Landing gear down
10.0
Car
I'm a sedan
Moving
10.0
public class Main{
public static void main(String[] args){
Vehicle car = new Car("Car", 4);
System.out.println(car.honk_horn());
}
}
public class Main{
public static void main(String[] args){
Vehicle car = new Car("Car", 4);
System.out.println(car.honk_horn());
}
}
public class Main{
public static void main(String[] args){
Vehicle car = new Car("Car", 4);
System.out.println(car.honk_horn());
}
}
public class Main{
public static void main(String[] args){
Vehicle car = new Car("Car", 4);
System.out.println(car.honk_horn());
}
}
public class Main{
public static void main(String[] args){
Vehicle car = new Car("Car", 4);
System.out.println(car.honk_horn());
}
}
public class Main{
public static void main(String[] args){
Vehicle car = new Car("Car", 4);
System.out.println(car.honk_horn());
}
}
Rules
- Store any child class within parent class variable
- Use attributes and methods based on data type of variable, regardless of type stored
- Overriden methods will use code in child class even when stored as parent data type
public class Main{
public static void main(String[] args){
Vehicle[] array = new Vehicle[3];
array[0] = new Airplane("Plane", 123, 45);
array[1] = new Car("Car", 4);
array[2] = new Truck("Truck", 157);
for(Vehicle v : array){
System.out.println(v.getName());
System.out.println(v.describe());
System.out.println(v.move(10));
}
}
}