HYDERABAD INSTITUTE OF ARTS, SCIENCE, AND TECHNOLOGY
HYDERABAD INSTITUTE OF ARTS, SCIENCE, AND TECHNOLOGY
Object Oriented Programming Lab-07
Lab Title:
Abstraction Using Abstract Classes in Java
1. Objective
This lab aims to introduce the concept of Abstraction in Object-Oriented Programming using
Abstract Classes in Java. Students will learn how to hide implementation details while exposing
only essential functionality through abstract methods and concrete implementations.
2. Introduction
Abstraction is one of the four fundamental principles of Object-Oriented Programming (OOP). It is
the process of hiding implementation details and exposing only the essential features of an object.
In Java, abstraction can be achieved using Abstract Classes and Interfaces. An abstract class cannot
be instantiated directly. It serves as a blueprint for other classes by containing both abstract methods
(without implementation) and concrete methods (with implementation).
A subclass that extends an abstract class must implement all of its abstract methods unless it is also
declared abstract.
Abstraction helps simplify complex systems, promotes code reusability, and improves software
maintainability.
3. Required Tools
• JDK (Java Development Kit)
• Apache NetBeans / IntelliJ IDEA / VS Code
• Java Compiler
• Terminal or Console Output Window
4. Project Structure
abstraction_lab/
└── [Link]
5. Implementation
Task 1: Abstract Class
abstract class Shape {
abstract void calculateArea();
void display() {
[Link]("Area Calculation");
}
}
class Circle extends Shape {
double radius = 5;
@Override
void calculateArea() {
double area = 3.1416 * radius * radius;
[Link]("Circle Area = " + area);
}
}
public class AbstractionDemo {
public static void main(String[] args) {
Circle c = new Circle();
[Link]();
[Link]();
}
}
Sample Output
Area Calculation
Circle Area = 78.54
Task 2: Abstract Class with Multiple Subclasses
abstract class Animal {
abstract void sound();
}
class Dog extends Animal {
@Override
void sound() {
[Link]("Dog Barks");
}
}
class Cat extends Animal {
@Override
void sound() {
[Link]("Cat Meows");
}
}
public class AnimalDemo {
public static void main(String[] args) {
Animal a1 = new Dog();
Animal a2 = new Cat();
[Link]();
[Link]();
}
}
Sample Output
Dog Barks
Cat Meows
6. Student Tasks
Task 1
Create an abstract class Vehicle containing the abstract method:
startEngine()
Create the following subclasses:
• Car
• Bike
• Bus
Implement the startEngine() method in each class.
Task 2
Create an abstract class Employee with the abstract method:
calculateSalary()
Create subclasses:
• FullTimeEmployee
• PartTimeEmployee
Display the calculated salary.
Task 3
Create an abstract class Bank containing:
calculateInterest()
Create subclasses:
• HBL
• Meezan Bank
• UBL
Display different interest rates.
Task 4
Create an abstract class Payment with:
makePayment()
Create subclasses:
• CreditCard
• DebitCard
• JazzCash
Implement different payment methods.
7. Learning Outcomes
After completing this lab, students will be able to:
• Understand the concept of abstraction.
• Create abstract classes and abstract methods.
• Differentiate between abstract and concrete methods.
• Implement abstract methods using inheritance.
• Design modular and maintainable Java applications.
8. Conclusion
This lab demonstrated the implementation of abstraction using abstract classes in Java. Students
learned how abstract classes define a common blueprint while allowing subclasses to provide
specific implementations. Abstraction improves software design by reducing complexity, increasing
flexibility, and promoting reusable, maintainable object-oriented applications.