0% found this document useful (0 votes)
2 views1 page

Classes, Homework

The document outlines key concepts in object-oriented programming, including classes, inheritance, encapsulation, polymorphism, overriding, instance variables, and class variables. Each concept is defined with a brief explanation and an example for clarity. These principles are essential for creating and managing objects in programming.

Uploaded by

tanakamashevedze
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)
2 views1 page

Classes, Homework

The document outlines key concepts in object-oriented programming, including classes, inheritance, encapsulation, polymorphism, overriding, instance variables, and class variables. Each concept is defined with a brief explanation and an example for clarity. These principles are essential for creating and managing objects in programming.

Uploaded by

tanakamashevedze
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

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.

You might also like