PPL Assignment
PPL Assignment
PPL ASSIGNMENT
Encapsulation:-
Data Hiding: Encapsulation allows the internal state of an object to be hidden from the outside
world. The data is typically declared as private or protected within the class, preventing direct
access or modification by external code. Instead, access to the data is controlled through public
methods, also known as accessors or getters, which provide a controlled interface for interacting
with the object's state.
Data Integrity: By encapsulating data within a class and providing controlled access through
methods, encapsulation helps maintain data integrity and prevents accidental or unauthorized
modifications to the object's state. Methods can include validation logic to ensure that data is
consistent and valid before allowing changes to be made.
Code Flexibility and Maintainability: Encapsulation promotes code modularity and separation of
concerns by grouping related data and behavior together within a class. This makes the code
easier to understand, maintain, and extend, as changes to one part of the code are less likely to
have unintended consequences on other parts.
Encapsulation vs. Information Hiding: While encapsulation often involves information hiding (by
making data private or protected), the two concepts are not identical. Encapsulation
encompasses the broader idea of bundling data and methods into a single unit, whereas
information hiding specifically refers to the practice of restricting access to certain parts of the
object's internal state.
Abstraction
Polymorphism:-
Polymorphism, in the context of object-oriented programming (OOP), refers to the ability of
different objects to respond to the same message or method invocation in different ways. This
concept allows objects of different classes to be treated as objects of a common superclass,
enabling flexibility, extensibility, and code reuse.
There are two main types of polymorphism:
Integer: Represents whole numbers without fractional parts. Examples include 0, 1, -5, 100, etc.
Floating-point: Represents numbers with fractional parts. Examples include 3.14, -0.5, 2.71828,
etc.
Boolean: Represents a logical value that can be either true or false.
String: Represents a sequence of characters. Examples include "hello", "world", "12345", etc.
Array: Represents a collection of elements of the same type stored in contiguous memory
locations.
Pointer: Represents a memory address, typically used to store the location of another variable or
object in memory.
Struct or Record: Represents a composite data type that groups together variables of different
types under a single name.
Enumeration: Represents a set of named constant values, often used to define custom data
types with a limited set of possible values.
Void: Represents the absence of a data type, often used to indicate that a function does not
return a value or that a pointer does not point to any specific type.