Professional Documents
Culture Documents
Course Objectives
Information hiding
Class A class is a blueprint that defines the variables and the methods common
to all objects of a certain kind.
Gives a general description of objects (blueprint).
Establishes status types (attributes) and behavior (methods)
When a real world entity is modeled into OOP world then it is known as Class,
characteristics as attributes and functionality as methods
Class
Desktop PC Instance
Attributes Lenovo PC
Display type Attributes
HDD capacity
Display type - LCD
RAM size
Processor Speed HDD capacity 160GB
RAM size 1GB
Methods
Processor Speed Dual Core
Switch On
Switch Off
Encapsulation
Packaging an objects variables (attributes) within the protective custody of its methods.
called encapsulation. For ex. if we consider an instance as a cell the variables (attributes)
form the core nucleus and the methods surround these attributes.
Benefits of Encapsulation
Encapsulating related variables and methods into a neat software bundle is a simple yet
powerful idea that provides two benefits to software developers:
Modularity: The source code for an object can be written and maintained independently of
the source code for other objects. Also, an object can be easily passed around in the
system. You can give your bicycle to someone else, and it will still work.
Information-hiding: An object has a public interface that other objects can use to
communicate with it. The object can maintain private information and methods that can be
changed at any time without affecting other objects that depend on it.
Encapsulation
Benefits of Encapsulation
Inheritance
Inheritance
The term inheritance refers to the fact that one class can inherit part or all of its structure and
behavior from another class. The class that does the inheriting is said to be a subclass of the
class from which it inherits. If class B is a subclass of class A, we also say that class A is a
superclass of class B. A subclass can add to the structure and behavior that it inherits. It can
also replace or modify inherited behavior (though not inherited structure). The relationship
between subclass and superclass is sometimes shown by a diagram in which the subclass is
shown below, and connected to, its superclass.
Inheritance
The term inheritance refers to the fact that one class can inherit part or all of its
structure and behavior from another class.
The class that does the inheriting is said to be a subclass of the class from which
it inherits.
If class B is a subclass of class A, we also say that class A is a superclass of
class B.
A subclass can add to the structure and behavior that it inherits.
It can also replace or modify inherited behavior (though not inherited structure).
The relationship between subclass and superclass is sometimes shown by a
diagram in which the subclass is shown below, and connected to, its superclass.
Superclass
Subclass
Polymorphism
Polymorphism just means that different objects can respond to the same message
in different ways.
METHOD ADD
(Addition Operation is
performed) (Concatenation Operation is
performed)
Access modifiers
Public components
Visible to all direct access
Protected components
Only visible within their class and within
the subclass
Private components
Only visible within the class
No access from outside the class, not
even from the subclass
Thank You
Questions