Group - 5 JAVA ASSIGNMENT
Group - 5 JAVA ASSIGNMENT
Inheritance is the concept in OOPs in which one class inherits the attributes and methods of
another class. The class whose properties and methods are inherited is known as the Parent class.
And the class that inherits the properties from the parent class is the Child class. It is a
fundamental concept in OOP that promotes code reuse and establishes relationships between
classes.
// Parent class
class Vehicle {
this.brand = brand;
this.color = color;
super(brand, color);
this.numDoors = numDoors;
super(brand, color);
this.hasSidecar = hasSidecar;
// Main class
System.out.println();
In this program, we have a parent class called Vehicle with a constructor and a method
displayInfo() that prints the brand and color of the vehicle. The Car and Motorcycle classes
inherit from the Vehicle class using the extends keyword.
The Car class has an additional property numDoors and overrides the displayInfo() method to
include the number of doors in the output.
The Motorcycle class has an additional property hasSidecar and also overrides the displayInfo()
method to include whether or not it has a sidecar.
In the main method, we create objects of Car and Motorcycle and call their respective
displayInfo() methods. The output will demonstrate how the child classes inherit properties and
methods from the parent class.
Question C
}
In this program, we have an OverloadExample class with a main() method. The program declares
four variables: int1 and int2 for integers, and float1 and float2 for floating-point numbers.
The max() method is overloaded, which means we have two methods with the same name but
different parameter types. The first max() method takes two int parameters and uses the
Math.max() method to determine the maximum value between the two integers. The second
max() method takes two float parameters and uses the Math.max() method to determine the
maximum value between the two floating-point numbers.
In the main() method, we call the overloaded max() methods with the given integer and floating-
point values. The returned maximum values are stored in maxInt and maxFloat variables,
respectively.