18 changed files with 63 additions and 0 deletions
Binary file not shown.
@ -0,0 +1,6 @@ |
|||||
|
public class Bike extends Vehicle { |
||||
|
@Override |
||||
|
public void run() { |
||||
|
System.out.println("Bike is running on the road"); |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,6 @@ |
|||||
|
public class Car extends Vehicle { |
||||
|
@Override |
||||
|
public void run() { |
||||
|
System.out.println("Car is running on the road"); |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,6 @@ |
|||||
|
public class Circle extends Shape { |
||||
|
@Override |
||||
|
public void draw() { |
||||
|
System.out.println("Drawing a Circle"); |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,6 @@ |
|||||
|
public class Rectangle extends Shape { |
||||
|
@Override |
||||
|
public void draw() { |
||||
|
System.out.println("Drawing a Rectangle"); |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,5 @@ |
|||||
|
public class Shape { |
||||
|
public void draw() { |
||||
|
System.out.println("Drawing a shape"); |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,13 @@ |
|||||
|
public class ShapeTest { |
||||
|
public static void drawShape(Shape s) { |
||||
|
s.draw(); |
||||
|
} |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
Shape c = new Circle(); |
||||
|
Shape r = new Rectangle(); |
||||
|
|
||||
|
drawShape(c); |
||||
|
drawShape(r); |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,6 @@ |
|||||
|
public class Truck extends Vehicle { |
||||
|
@Override |
||||
|
public void run() { |
||||
|
System.out.println("Truck is running on the road"); |
||||
|
} |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,3 @@ |
|||||
|
public abstract class Vehicle { |
||||
|
public abstract void run(); |
||||
|
} |
||||
Binary file not shown.
@ -0,0 +1,12 @@ |
|||||
|
public class VehicleTest { |
||||
|
public static void main(String[] args) { |
||||
|
Vehicle[] vehicles = new Vehicle[3]; |
||||
|
vehicles[0] = new Car(); |
||||
|
vehicles[1] = new Bike(); |
||||
|
vehicles[2] = new Truck(); |
||||
|
|
||||
|
for (Vehicle v : vehicles) { |
||||
|
v.run(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue