Object Oriented Program
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.
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
Examples:
Employee works-for
a. Binary Association
It associates objects of exactly two classes; it is denoted by a
line, or an arrow between the associated objects.
Example
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;
}