0% found this document useful (0 votes)
4 views3 pages

Java 2

The document outlines an experiment focused on designing a class hierarchy for a library system using object-oriented programming concepts in Java. It emphasizes inheritance, polymorphism, encapsulation, and composition by implementing classes for different types of books and a Library class to manage them. The goal is to demonstrate OOP principles while simulating a basic library system capable of managing various book types.

Uploaded by

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

Java 2

The document outlines an experiment focused on designing a class hierarchy for a library system using object-oriented programming concepts in Java. It emphasizes inheritance, polymorphism, encapsulation, and composition by implementing classes for different types of books and a Library class to manage them. The goal is to demonstrate OOP principles while simulating a basic library system capable of managing various book types.

Uploaded by

shubham kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment 1

Student Name: Amarjeet Raj UID:23BCS13589


Branch: BE-CSE Section/Group:608-A
Semester: 4th Date of Performance:25th Jan,2025
Subject Name:OOP using Java Subject Code:23CST-202

Aim:-

In a library, there are different types of books like Textbooks, Novels, and Reference
Books. Each book has properties like title, author, and ISBN.
Textbooks have an additional property for the subject, and Reference Books have an
additional property for the edition.
Task: Design a class hierarchy using inheritance. Implement classes Book, Text Book, and
Reference Book. Use methods to add books and display their details.

Objective:-

1. Inheritance and Polymorphism:


o Book is a base class that represents a general book with properties such as title,
author, and isbn.
o TextBook and ReferenceBook are subclasses of Book that extend its
functionality by adding specific properties (subject for TextBook and edition for
ReferenceBook) and overriding the displayDetails() method to include these
additional details.
2. Encapsulation:
o The properties of each class are encapsulated and accessed through constructors
and methods, ensuring controlled access and data integrity.
3. Composition:
o The Library class manages a collection of Book objects using a List to represent
the library's inventory.
4. Code Reusability:
o The displayDetails() method in the base Book class is reused and extended in
the subclasses, reducing code duplication and promoting modularity.
Functionality:
 The Library class allows adding books (addBook()) and displaying all books
(displayAllBooks()).
 The main() method creates a Library instance, adds instances of Book, TextBook, and
ReferenceBook to it, and then displays their details using polymorphism.

The primary goal is to demonstrate object-oriented programming (OOP) concepts and


simulate a basic library system capable of managing different types of books. It shows how
to structure a program using inheritance, method overriding, and dynamic behavior based
on object types.
Java Code:
Output:

You might also like