Question: public class Vehicle { public void move(){System. out .println( Vehicles can move!! );} } public class MotorBike extends Vehicle { MotorBike(){ System. out .println( A
public class Vehicle {
public void move(){System.out.println("Vehicles can move!!");}
}
public class MotorBike extends Vehicle {
MotorBike(){ System.out.println("A motorbike is produced ");}
public void move(){
System.out.println("MotorBike can move and accelerate too!"); }
}
public class Car extends Vehicle {
public Car(){System.out.println("A car is produced"); }
public void move(){
System.out.println("Car is faster than Motorbike!!"); }
}
public class Main {
public static void main(String[] args) {
Vector v = new Vector();
Vehicle v1,v2,v3;
v1= new MotorBike();
v.add(v1);
v2=new Car();
v.add(v2);
for (int i=0;i < v.size();i++) {
v3 = (Vehicle) v.get(i);
v3.move();
}
}
}
a.) (5p) if you run Main, what will be printed on the screen
b.) (15p) Draw UML diagrams for classes Car, Vehicle and Motorbike
c.) (5p) write a new class to represent a sport car
Attention : The language is JAVA
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
