HOMEWORK
Class
A class is a blueprint or template used to create objects in programming. It defines the
properties (variables) and behaviors (methods) that objects will have.
Example: A Car class can define color, speed, and methods like drive or stop.
Inheritance
Inheritance is a feature where one class acquires the properties and methods of another class.
It promotes code reuse and creates relationships between classes.
Example: A Dog class inheriting from an Animal class.
Encapsulation
Encapsulation is the process of hiding data inside a class and allowing access through methods.
It protects data from unauthorized access or modification.
Example: Using private variables with getter and setter methods.
Polymorphism
Polymorphism means “many forms.” It allows the same method or function name to perform
different tasks depending on the object or context.
Example: A draw() method behaving differently for Circle and Rectangle classes.
Overriding
Overriding occurs when a subclass provides its own version of a method already defined in the
parent class. This allows specialized behavior.
Example: A Bird class overriding the sound() method from Animal.
Instance Variable
An instance variable is a variable declared inside a class but outside methods, and each object
has its own separate copy.
Example: Each student object having its own name and age.
Class Variable
A class variable is shared among all objects of a class. It belongs to the class rather than
individual instances.
Example: A variable counting the total number of students created.