KEMBAR78
Assignment Oop 5 | PDF
0% found this document useful (0 votes)
14 views2 pages

Assignment Oop 5

The document contains Java code that defines an interface 'Vehicle' with methods for changing gears, speeding up, and applying brakes. Three classes, 'Car', 'Bicycle', and 'Bike', implement the 'Vehicle' interface, each providing specific implementations for the methods. The main class 'Abc' demonstrates the functionality of these classes by creating instances and invoking their methods.

Uploaded by

joshishridhar186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Assignment Oop 5

The document contains Java code that defines an interface 'Vehicle' with methods for changing gears, speeding up, and applying brakes. Three classes, 'Car', 'Bicycle', and 'Bike', implement the 'Vehicle' interface, each providing specific implementations for the methods. The main class 'Abc' demonstrates the functionality of these classes by creating instances and invoking their methods.

Uploaded by

joshishridhar186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.io.

*;

interface Vehicle
{
int speed=40;
int gear=1;
int breaks=0;
void Gear_change(int a);
void SpeedUp(int b);
void apply_break();
}

class Car implements Vehicle


{
public void Gear_change(int a)
{
System.out.println("Gear change : "+(gear+a));
}

public void SpeedUp(int b)


{
System.out.println("Car speed : "+(speed+b));
}

public void apply_break()


{
System.out.println("apply_break : "+breaks);
}
}

class Bicycle implements Vehicle


{

public void Gear_change(int a)


{
System.out.println("Gear change : "+a);
}

public void SpeedUp(int b)


{
System.out.println("Bicycle speed : "+(speed+b));
}

public void apply_break()


{
System.out.println("apply_break : "+breaks);
}

}
class Bike implements Vehicle
{
public void Gear_change(int a)
{
System.out.println("Gear change : "+(gear+a));
}

public void SpeedUp(int b)


{
System.out.println("Bike speed : "+(speed+b));
}

public void apply_break()


{
System.out.println("apply_break : "+breaks);
}
}

public class Abc


{
public static void main(String[]args)
{
Car c1=new Car();
c1.Gear_change(3);
c1.SpeedUp(100);
c1.apply_break();
Bicycle bc=new Bicycle();
bc.Gear_change(1);
bc.SpeedUp(40);
bc.apply_break();
Bike b=new Bike();
b.Gear_change(3);
b.SpeedUp(90);
b.apply_break();
}
}

You might also like