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

Java Ass6

The document presents a Java program assignment focused on abstract classes and inheritance. It defines an abstract class 'Vehicle' with an abstract method 'engine()', which is implemented by two subclasses, 'Car' and 'Truck', each providing distinct outputs. The program illustrates the principles of abstraction and inheritance in Java programming.

Uploaded by

31240631
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)
9 views3 pages

Java Ass6

The document presents a Java program assignment focused on abstract classes and inheritance. It defines an abstract class 'Vehicle' with an abstract method 'engine()', which is implemented by two subclasses, 'Car' and 'Truck', each providing distinct outputs. The program illustrates the principles of abstraction and inheritance in Java programming.

Uploaded by

31240631
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

BTECAD24405:: Technology Skill Dev.

-2 (Java)
Assignment No. – 6
Name- Nidhi Haridas
Roll no. – 28
Division-C
Batch –C2
Class - SY
Branch -AIML
Course Teacher Name - Prof. Mayuri Satpute
Assignment 6:
Write a Java program in which you will declare an abstract class Vehicle inherits this class from two
classes car and truck using the method engine in both displays “car has good engine” and “truck
has bad engine”..

CODE:
// Abstract Class

abstract class Vehicle {

// Abstract Method

abstract void engine();

// Car Class inheriting Vehicle

class Car extends Vehicle {

void engine() {

[Link]("Car has good engine");

// Truck Class inheriting Vehicle

class Truck extends Vehicle {

void engine() {

[Link]("Truck has bad engine");

}
// Main Class

public class Main {

public static void main(String[] args) {

Car c = new Car();

Truck t = new Truck();

[Link]();

[Link]();

}
Output:

Conclusion:
This program demonstrates the use of an abstract class in Java. The abstract class
Vehicle defines the abstract method engine(), which is implemented differently by the
Car and Truck classes. This shows how inheritance and abstraction allow different
classes to provide their own implementation of a common method.

You might also like