- Create a base class
Person
with attributesname
andage
. - Derive two classes,
Student
andTeacher
, fromPerson
. - Include appropriate constructors and methods in each class.
- Demonstrate polymorphism by creating an array of
Person
objects and displaying information for each.
- Design a class
BankAccount
with private attributesaccountNumber
,balance
, andaccountHolderName
. - Encapsulate these attributes using getter and setter methods.
- Implement a method
withdraw(double amount)
to deduct money from the account balance. - Create instances of the
BankAccount
class and demonstrate encapsulation and abstraction.
- Define an interface
Drawable
with a methoddraw()
. - Create classes
Circle
andSquare
that implement theDrawable
interface. - Add unique methods to each class (e.g.,
calculateArea()
forCircle
andcalculatePerimeter()
forSquare
). - Demonstrate polymorphism by creating an array of
Drawable
objects and calling thedraw()
method on each.
- Create a class
Library
with attributesname
and a list ofBook
objects. - Implement a method in the
Library
class to add a book to its collection. - Create instances of the
Library
andBook
classes and showcase composition.
- Create a class
TemperatureConverter
with a methodconvertToFahrenheit(double celsius)
that converts Celsius to Fahrenheit. - Implement exception handling to handle invalid temperature values.
- Demonstrate the usage of the
TemperatureConverter
class with different scenarios.
- Create a class
Car
with a static variabletotalCars
to keep track of the number of cars created. - Implement a non-static method
startEngine()
that prints a message indicating the engine has started. - Demonstrate the usage of both static and non-static members.