Experiment No 4
Experiment No 4
Date:
CO mapped: CO-2
Objectives:
Background:
Object means a real-world entity such as a pen, chair, table, computer, watch, etc. Object-
Oriented Programming is a methodology or paradigm to design a program using classes and
objects. Inheritance in Java is a mechanism in which one object acquires all the properties
and behaviors of a parent object. It is an important part of OOPs (Object Oriented
programming system). The idea behind inheritance in Java is that you can create new classes
that are built upon existing classes. When you inherit from an existing class, you can reuse
methods and fields of the parent class. Moreover, you can add new methods and fields in
your current class also.
Terms used in Inheritance
Practical questions:
1. A set of 5 words (strings) will be taken as command line arguments. Write a program
to reverse each word and check whether it is palindrome or not using method.
2. Define the class BankAccount to represent an account we open with bank. Define the
subclasses SavingAccount and FixedDepositAccount. Implement the operations like
openAccount(), deposit(), checkBalance(), withdraw() and calInterest() for these
classes.
3. Write a program that finds area of any shape by overloading area () method for
Square, Rectangle, Triangle and Square.
4. Write a program that finds Volume of any shape by overloading volume () method for
Cube, Rectangular Cube and Sphere.
5. Write a Program to maintain employee’s information. Program should illustrate
Inheritance concept. (Use your imagination to create class or subclass used for
employee).
6. Create a base class Shape. Use this class to store two double type values that could be
used to compute area of any shape. Derive two specific classes called Triangle and
Rectangle from the base shape. Add to the base a member function getdata() to
initialize base class data member and another member function display_area() to
compute and display the area of figures. (Use Method Overriding).
Conclusion:
Quiz:
1. What is inheritance in java? Explain different types of inheritance with proper example.
2. Explain the use of final and Super keyword in JAVA
3. Define polymorphism with its need.
4. Explain about Encapsulation, Abstraction.
Suggested Reference:
1. https://www.tutorialspoint.com/java/
2. https://www.geeksforgeeks.org/
3. https://www.w3schools.com/java/
4. https://www.javatpoint.com/