Oop 5
Oop 5
05
Name:
Roll.No.:
/* Design and develop a context for given case study and implement an interface for Vehicles Consider
the example of vehicles like bicycle, car and bike. All Vehicles have common functionalities such as
Gear Change, Speed up and apply breaks. Make an interface and put all these common functionalities.
Bicycle, Bike, Car classes should be implemented for all these functionalities in their own class in their
own way. */
Source Code :
import java.util.*;
interface Vehicles
{
void speedUp();
void applyBreaks();
void gearChange();
}
class Interfaces
{
public static void main(String[] args) {
Vehicles v;
v= new Bycicle();
System.out.println("--Bycicle--");
v.gearChange();
v.speedUp();
v.applyBreaks();
v= new Bike();
System.out.println("--Bike--");
v.gearChange();
v.speedUp();
v.applyBreaks();
v= new Car();
System.out.println("--Car--");
v.gearChange();
v.speedUp();
v.applyBreaks();
}
}
Output :
--Bycicle--
Enter Gear : 1
Gear changed of Bycicle:2
Enter speed : 20
Speed of Bycicle is changed to :30
Applied breaks of Bycicle
--Bike--
Enter Gear : 2
Gear changed of Bike to :3
Enter speed : 60
Speed of Bike is changed to: 70
Applied breaks of Bike
--Car--
Enter Gear : 3
Gear changed of Car: 4
Enter speed : 80
Speed of Car is changed to:90
Applied breaks of Car