0% found this document useful (0 votes)
3 views2 pages

Java Exp3

The document outlines an experiment focused on creating Java programs that demonstrate inheritance and polymorphism. It includes a sample code for a 'Vehicle' class and a 'Car' subclass, showcasing the use of inherited attributes. The output confirms the successful implementation of speed and wheel count for the Car object.

Uploaded by

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

Java Exp3

The document outlines an experiment focused on creating Java programs that demonstrate inheritance and polymorphism. It includes a sample code for a 'Vehicle' class and a 'Car' subclass, showcasing the use of inherited attributes. The output confirms the successful implementation of speed and wheel count for the Car object.

Uploaded by

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

Experiment No.

:-04 Date:-11-03-26
Name:- ASHISH RANJAN Roll No.:-2401320100102

OBJECTIVE:-
Create Java Programs using inheritance and polymorphism.
CODE:-
class Vehicle {
int speed = 120;
}

class Car extends Vehicle {


int wheels = 4;
}

public class TestInheritance {


public static void main(String[] args) {
Car c1 = new Car();

[Link]("Speed: " + [Link]);


[Link]("Number of Wheels: " + [Link]);
}
}
TO COMPILE:-

TO RUN:-

OUTPUT:-
Speed: 120
Number of Wheels: 4

1
Sign:-
Experiment No.:-04 Date:-11-03-26
Name:- ASHISH RANJAN Roll No.:-2401320100102

POLYMORPHISM:-
[Link] Overriding:-

2
Sign:-

You might also like