0% found this document useful (0 votes)
20 views

Object Oriented Program

The document discusses key concepts of object oriented programming including inheritance, abstraction, encapsulation, and information hiding. Inheritance allows a child class to inherit characteristics from a parent class, while also having its own unique characteristics. Abstraction involves capturing only relevant details about an object from a given perspective. Encapsulation groups data and functions into a single unit called an object, providing simplicity, clarity and low complexity. Information hiding principles involve storing all object information within the object and hiding it from outside users.

Uploaded by

sonubukhari9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Object Oriented Program

The document discusses key concepts of object oriented programming including inheritance, abstraction, encapsulation, and information hiding. Inheritance allows a child class to inherit characteristics from a parent class, while also having its own unique characteristics. Abstraction involves capturing only relevant details about an object from a given perspective. Encapsulation groups data and functions into a single unit called an object, providing simplicity, clarity and low complexity. Information hiding principles involve storing all object information within the object and hiding it from outside users.

Uploaded by

sonubukhari9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Object Oriented Program

i) Inheritance
A child inherits characteristics of its parents,
besides inherited characteristics, a child may have its own
unique characteristics.
The parent class is called base class and the child
class is called derived class.
Example
Person

Student Doctor
Teacher

Shape

Line Triangle

Circle
ii) Principle of abstraction:
“Capture only those details about an object that are
relevant to current perspective”
Abstraction Example:
“Ali is a PhD student and teaches BS students”
Here object Ali has two Perspectives one is his student
perspective and second is his teacher perspective.

We can sum up Ali’s attributes as follows,


Name
Age
Student Roll No
Year of Study
CGPA
Employee ID
iii) Advantages of Encapsulation
a. Simplicity and clarity
As all data and functions are stored in the objects so there is no
data or function around in program that is not part of any object.
b. Low complexity
As data members and functions are hidden in objects and each
object has a specific behavior so there is less complexity in
code.
c. Better understandings
Every will be able to understand whole scenario by simple
looking into object
Diagrams without any issue as each object has specific role and
specific relation with other objects.

iv. Information hiding in OOP.


In object oriented programming approach we have objects with
their attributes and behaviors that are hidden from other class,
so we can say that object oriented programming follows the
principle of information hiding.
“Hiding the object details (state and behavior) from the users”

Principles:
 All information related to an object is stored within the object.
 It is hidden from the outside world.

Long Questions
1. Simple association with their types
Simple association:
The two interacting objects have no intrinsic relationship
with other object. It is the weakest link between objects. It is a
reference by which one object can interact with some other
object.
Ali lives in a house
Ali drives a car
Ali lives-in House
1

Ali drives Car


1
It is generally called as “association” instead of “simple association”
Kinds of Simple Association
Simple association can be categorized two ways,
 With respect to direction (navigation)
 With respect to number of objects (cardinality)

Kinds of Simple Association w.r.t Navigation


a. One-way Association
b. Two-way Association
a. One-way Association
In one way association we can navigate along a single direction
only, it is denoted by an arrow towards the server object.

Examples:

Ali lives-in House

 Ali lives in a House

Ali drives Car

 Ali drives his Car


b.Two-way Association
In two way association we can navigate in both directions, it is
denoted by a line between the associated objects.
Examples:

Employee works-for

Employee works for company


Company employs employees

Kinds of Simple Association w.r.t Cardinality


Types:
a. Binary Association
b. Ternary Association
c. N-ary Association

a. Binary Association
It associates objects of exactly two classes; it is denoted by a
line, or an arrow between the associated objects.
Example

Employee works-for Company

Association “works-for” association objects of exactly two classes


Ternary Association
It associates objects of exactly three classes; it is denoted by a
diamond with lines connected to associated objects.
Student Teacher

Course

N-ary Association
An association between 3 or more classes its practical examples
are very rare.
2. Write a program with multiple
inheritance class of woman and
mermaid walk and swim.
#include<iostream>
using namespace std;
#include<conio.h>
class Fish
{
public:
void swim(){
cout<<"In method swim";
}
};
class Woman
{
public:
void walk(){
cout<<"\n In method walk"<<endl;
}

};
class Mermaid:public Woman,public Fish
{

};
int main()
{
Mermaid mermaid;
mermaid.swim();
mermaid.walk();
getch ();
return 0;
}

You might also like