5 changed files with 54 additions and 0 deletions
@ -0,0 +1,9 @@ |
|||||
|
public class Bike extends Vehicle{ |
||||
|
protected Bike(String name){ |
||||
|
this.s=name; |
||||
|
} |
||||
|
@Override |
||||
|
public void run(){ |
||||
|
System.out.println(s+" is running"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
public class Car extends Vehicle { |
||||
|
protected Car(String name){ |
||||
|
this.s=name; |
||||
|
} |
||||
|
@Override |
||||
|
public void run(){ |
||||
|
System.out.println(s+" is running"); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,6 @@ |
|||||
|
public class Circle extends Shape{ |
||||
|
@Override |
||||
|
protected void draw(){ |
||||
|
System.out.println("Circle is drawn."); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,5 @@ |
|||||
|
public class DrawShape { |
||||
|
public static void drawshape(Shape s){ |
||||
|
s.draw(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
public class Main { |
||||
|
public static void main(){ |
||||
|
Shape c=new Circle(); |
||||
|
Shape r=new Retangle(); |
||||
|
DrawShape.drawshape(c); |
||||
|
DrawShape.drawshape(r); |
||||
|
Vehicle[] bikes=new Bike[5]; |
||||
|
Vehicle[] cars=new Car[5]; |
||||
|
Vehicle[] trucks=new Truck[5]; |
||||
|
for (int i=0;i<5;i++){ |
||||
|
bikes[i]=new Bike("bike"+(i+1)); |
||||
|
cars[i]=new Car("car"+(i+1)); |
||||
|
trucks[i]=new Truck("truck"+(i+1)); |
||||
|
} |
||||
|
for(Vehicle bike:bikes){ |
||||
|
bike.run(); |
||||
|
} |
||||
|
for(Vehicle car:cars){ |
||||
|
car.run(); |
||||
|
} |
||||
|
for(Vehicle truck:trucks){ |
||||
|
truck.run(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue