Lab Session 05
Criterion1 Criterion2 Criterion3 Criterion4 Criterion5 Total
/20
Lab Title: Practice with Inheritance.
1. Problem Statement
Create a simple Vehicle Management System to demonstrate inheritance. The system should categorize
different types of vehicles while reusing common properties and behaviors from a parent class.
2. Objectives
By the end of this lab, students will:
1. Understand inheritance hierarchy
2. Practice method overriding
3. Learn super keyword usage
4. Create parent-child class relationships
1. public class inheritance{
2. public static void main(String[] args) {
3. Car honda = new Car();
4. [Link]("2024");
5. [Link]("5 year");
6. [Link]("civic");
7. ElectricCar tesla = new ElectricCar();
8. [Link]("Model S");
9. [Link]("4 years");
10. [Link]("fortuner");
11. [Link](6);
12.
13. [Link]("Car Details:");
14. [Link]("Name: " + [Link]());
15. [Link]("Model: " + [Link]());
16. [Link]("Warranty: " + [Link]());
17. [Link]("Capacity: " + [Link]());
18.
19. }
20. }
21. class Car {
22.
23. private String Warranty ,Model,name;
24. public void setmodel(String Model){
25. [Link]=Model;
26.
27. }
28. public String getmodel(){
29. return Model;
30. }
31. public void setWarranty(String Warranty){
32. [Link]=Warranty;
33.
34. }
35. public String getWarranty(){
36. return Warranty;
37. }
38. public void setname(String name){
39. [Link]=name;
40. }
41. public String getname(){
42. return name;
43. }
44.
45. }
46.
47. class ElectricCar extends Car{
48. private int Capacity;
49. public void setCapacity(int Capacity) {
50. [Link] = Capacity;
51. }
52. public int getCapacity() {
53. return Capacity;
54. }