[go: up one dir, main page]

0% found this document useful (0 votes)
7 views2 pages

Assignment 5

The document outlines a lab assignment focused on abstract classes and interfaces in Java. It explains the concepts of abstract classes, which cannot be instantiated and may contain abstract methods, and interfaces, which serve as contracts for classes. Three programming exercises are provided to implement these concepts using shapes, employee types, and bank accounts.

Uploaded by

Harsh Jha
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)
7 views2 pages

Assignment 5

The document outlines a lab assignment focused on abstract classes and interfaces in Java. It explains the concepts of abstract classes, which cannot be instantiated and may contain abstract methods, and interfaces, which serve as contracts for classes. Three programming exercises are provided to implement these concepts using shapes, employee types, and bank accounts.

Uploaded by

Harsh Jha
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/ 2

Jaypee Institute of Information Technology

Object Oriented Programming Using Java(24B15CS215)


Lab Assignment -5

Experiment 5: Abstract Class, Interface - Part (I)

Abstract Class: A class that cannot be instantiated and may contain abstract
(unimplemented) methods. It is used when common base functionality is shared,
but some methods must be implemented by subclasses. It includes
o Abstract and non-abstract methods
o Constructors
o Static methods
o Instance variables

Example
abstract class Shape {
double dimension;
abstract double area(); // Abstract method
void setDimension(double d) { this.dimension = d; }
}

Interface: A contract that a class agrees to follow. All methods are implicitly public and
abstract (until Java 8+ allowed default and static). It is used for multiple inheritance and
type-based design.

Example
interface Drawable {
void draw();
}
class Circle implements Drawable
{
public void draw()
{
System.out.println("Drawing circle");
}
}
Program 1: Create a package of shapes with an abstract class Shape that has an abstract
method calculateArea(). Implement classes like Circle and Rectangle that inherit from Shape
and implement the method. Use a Printable interface to print the details.

Program 2: Create an abstract class Employee with a method calculateSalary(). Create


classes FullTimeEmployee and PartTimeEmployee to implement logic. Use the interface
Displayable for showing details.

Program 3: Design an abstract class BankAccount with an abstract method withdraw() and a
concrete method deposit(). Use the interface Taxable to calculate service tax.

You might also like