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

OOP Assignment

The assignment focuses on demonstrating core Object-Oriented Programming (OOP) concepts using an Animal class as the base. It requires the implementation of features such as inheritance, polymorphism, abstraction, encapsulation, and various relationships (association, aggregation, composition) in either C++ or Java. The system must include specific methods and class structures, showcasing the principles of OOP through practical coding examples.

Uploaded by

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

OOP Assignment

The assignment focuses on demonstrating core Object-Oriented Programming (OOP) concepts using an Animal class as the base. It requires the implementation of features such as inheritance, polymorphism, abstraction, encapsulation, and various relationships (association, aggregation, composition) in either C++ or Java. The system must include specific methods and class structures, showcasing the principles of OOP through practical coding examples.

Uploaded by

Mian Daniyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Object-Oriented Programming (OOP) Assignment

This assignment is designed to demonstrate all the core concepts and pillars of Object-
Oriented Programming (OOP), including:

- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
- Association
- Aggregation
- Composition
- Constructor / Destructor / Super Constructor
- Shallow Copy vs Deep Copy
- Interfaces

Assignment Statement
Design an OOP-based system using an Animal class as the base. The system must cover the
following concepts:

 1. Inheritance ("is-a" relationship)


Create a base class `Animal`. Derived classes like `Dog`, `Cat`, and `Bird` should extend
the `Animal` class, showcasing the "is-a" relationship.
 2. Polymorphism
Demonstrate both compile-time (method overloading) and runtime polymorphism
(method overriding) using `speak()` methods in derived classes.
 3. Abstraction
Use abstract classes and/or interfaces like `Flyable` and `Swimmable` with abstract
methods `fly()` or `swim()`.
 4. Encapsulation
Encapsulate all class properties like `name`, `age`, `species` using private access
modifiers and provide public getters/setters.
 5. Association
Show a simple association between a `Veterinarian` class and `Animal` class (e.g., vet
checks an animal).
 6. Aggregation ("has-a" relationship, lifetime independent)
A `Zoo` class should contain a list of `Animal` objects. The animals can exist outside the
zoo.
 7. Composition ("must-have" relationship, lifetime dependent)
Each `Animal` must have a `Heart` object. When the `Animal` object is destroyed, its
`Heart` should also be destroyed.
 8. Constructor, Destructor, Super Constructor
Implement default and parameterized constructors in each class. Use the `super()`
keyword to call the parent class constructor. Use destructors or finalize (language-
dependent) to display messages on object destruction.
 9. Shallow Copy vs Deep Copy
Demonstrate the difference by cloning an `Animal` object and modifying its composed
`Heart` object to observe behavior.
 10. Interface
Create an `AnimalActions` interface with methods like `eat()`, `sleep()`, and implement
them in all subclasses.

Instructions:
Implement the assignment in **C++** or **Java** (choose one). Use appropriate OOP syntax
and language-specific features.

Example Structure (Java style):

abstract class Animal implements AnimalActions {


private String name;
private int age;
private Heart heart; // Composition

public Animal(String name, int age) {


this.name = name;
this.age = age;
this.heart = new Heart();
}

public abstract void speak();

// Getters and Setters


}

class Dog extends Animal {


public Dog(String name, int age) {
super(name, age);
}

@Override
public void speak() {
System.out.println("Woof Woof");
}

public void guard() {}


}
interface AnimalActions {
void eat();
void sleep();
}

class Zoo {
private List<Animal> animals; // Aggregation

public void addAnimal(Animal a) {


animals.add(a);
}
}

You might also like