OOPs in Java – GUVI Task
Introduction
This blog explains the solutions for the OOPs in Java task provided by GUVI.
The task focuses on basic object-oriented programming concepts such as classes,
constructors, inheritance, and methods.
Question 1.1 – Person Class
A Person class is created with name and age as attributes.
- Default age is set to 18
- A parameterized constructor is used to initialize name and age
- A display method is used to print the details
Question 1.2 – Product Class
A Product class is created with pid, price, and quantity.
- Five product details are accepted from the user
- The product with the highest price is identified
- Total amount spent on all products is calculated using a method
Question 1.3 – Account Class
An Account class is created with balance as a data member.
- A no-argument constructor and a parameterized constructor are used
- Deposit and withdraw methods are implemented
- Balance is displayed after each operation
Question 1.4 – Inheritance (Person and Employee)
Inheritance is implemented using Person as a base class and Employee as a subclass.
- Employee inherits name and age from Person
- Additional attributes employeeId and salary are added
- super keyword is used to initialize parent class attributes
GitHub Repository
All Java programs for this task are available in my GitHub repository:
https://github.com/nagendranmahavigneshshree-commits/OOPs-in-Java-tasks-for-GUVI/tree/main
Conclusion
This task helped me understand important OOP concepts such as constructors,
methods, arrays of objects, and inheritance in Java.
Top comments (0)