Professional Documents
Culture Documents
Java Assignment 2
Java Assignment 2
Java Assignment 2
### Inheritance:
1. **Simple Inheritance:**
Create a base class "Person" with attributes like name and age. Derive two classes
"Student" and "Teacher" from the base class. Demonstrate inheritance by accessing the
attributes of the base class in the derived classes.
2. **Multilevel Inheritance:**
Design a class hierarchy for vehicles. Create a base class "Vehicle," a derived class "Car"
from "Vehicle," and another class "SportsCar" from "Car." Demonstrate multilevel
inheritance by accessing properties from different levels.
### Abstraction:
3. **Abstract Class:**
Define an abstract class "Shape" with abstract methods for calculating area and perimeter.
Implement this class in concrete classes like "Circle" and "Rectangle." Demonstrate
abstraction by calling the abstract methods.
### Encapsulation:
5. **Private Members:**
Design a class "Employee" with private attributes like salary and department. Implement
getter and setter methods to access and modify these private attributes. Demonstrate
encapsulation by restricting direct access to private members.
6. **Encapsulation in Constructors:**
Create a class "Person" with private attributes for name and age. Use a constructor to
initialize these attributes. Demonstrate encapsulation by ensuring that the attributes can only
be set during object creation.
### Polymorphism:
7. **Method Overloading:**
Develop a class "Calculator" with methods for addition, subtraction, and multiplication.
Implement method overloading to allow these methods to accept different numbers of
arguments.
8. **Operator Overloading:**
Create a class "Vector" that represents a 3D vector. Implement operator overloading for
addition and subtraction. Demonstrate how to add and subtract vectors.
### Constructors:
### Interfaces: