0% found this document useful (0 votes)
4 views3 pages

SmartVehicleSystem Java

The document contains a Java program that defines a vehicle hierarchy with classes for Vehicle, Car, Bike, and ElectricCar. It demonstrates the use of inheritance and interfaces, specifically showcasing the functionality of displaying vehicle brands and charging an electric car's battery. The main method creates instances of Car, Bike, and ElectricCar, displaying their details and actions.

Uploaded by

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

SmartVehicleSystem Java

The document contains a Java program that defines a vehicle hierarchy with classes for Vehicle, Car, Bike, and ElectricCar. It demonstrates the use of inheritance and interfaces, specifically showcasing the functionality of displaying vehicle brands and charging an electric car's battery. The main method creates instances of Car, Bike, and ElectricCar, displaying their details and actions.

Uploaded by

Sonu Jadhav
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Generated by: Java Viewer

package car;

class Vehicle {String brand;

Vehicle(String brand) {
[Link] = brand;
}

void display() {
[Link]("Brand: " + brand);
}
}

class Car extends Vehicle {

Car(String brand) {
super(brand);
}

void type() {
[Link]("This is a Car");
}
}

class Bike extends Vehicle {

Bike(String brand) {
super(brand);
}

void type() {
[Link]("This is a Bike");
}
}

interface ElectricVehicle {
void chargeBattery();
}

class ElectricCar extends Car implements ElectricVehicle {

ElectricCar(String brand) {
super(brand);
}

public void chargeBattery() {


[Link]("Battery is charging...");
}
}

public class SmartVehicleSystem {


public static void main(String[] args) {

Car car = new Car("Lamborghini");


[Link]();
[Link]();

[Link]();

Bike bike = new Bike("Kawasaki Z900");


[Link]();
[Link]();

[Link]();

ElectricCar eCar = new ElectricCar("Tesla");


[Link]();
[Link]();
[Link]();
}
}
~ Output

Brand : Lamborghini
This is a Car

Brand : Kawasaki Z900


This is a Bike

Brand : Tesla
This is a Car
Battery is charging...

You might also like