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

Class and Objec

oop basic concepts

Uploaded by

M Innamullah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Class and Objec

oop basic concepts

Uploaded by

M Innamullah
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Class and object

Class? It is a user defiened data type that has data member(veriable) and member
function(function). It act as blueprint .

Object? It can any thing person place or thing. It allowprogramers to use the
variables and functions from inside the class.

Why we use class? Class is used to represent real world entity(object) in


programing.

Advantages

 Organazingthe code
 Reuseability
 Save time and space

Constructor

It is a special type of method . It is automatically called when we create object


of class. Its name is same as class name. It has no return type.

Why we use it is mostly used for initilliazed data members(variables).

Types

 Perametrized constructor
 Non-Perametrized constructor
 Copy constructor(it is used to initilliazed data members of class using
the another object of same class. )

Polymorphism

Polmorphism means having many forms. It allow us to perform single action in


different ways. (man act as father son emploeee)
compile-time polymorphism

Function overloading
Same name function can be used many times . The compiler will decide which function
to call based on the types of function & number and types of arguments passed to the
function.

Operator overloading

the ability to provide the operators with a special meaning for a data type, this
ability is known as operator overloading. For example, we can overload an
operator '+' in a class like String so that we can concatenate two strings by just
using +

Virtual functions
It allows an object of a derived class to behave as if it were an object of the base class.

Inharitance

What is inharitance?

Inharitance is the way of extending parrant characteristics in childs;


Why? If we need to use some members of one class into another class we use
inheritance.

Advantages

1) Reduce the code length


2) Reuseability
3) Organize code
4) Readability

Types

Single/simple inharitance

One child class is derived from one parent class(father and son)

Multiple inharitance

Once child class is drived form multiple parent classes(person and employee are
two parent class and teacher is derived form these classes)

Multilevel inharitance

One child is drived from parent and this parent is also derived from another parent
class; EX :son , Father , Grand father , grand grand father

Hierarchical inharitance

One parent have multiple child and these child also have multiple childs

Hybirdinharitance(mixture of two types of inheritence)

inharitance in which we use two inharitance types like if we use hierarchical


inharitance and sigleinharitance
Abstraction: it hides the unnecessary detail but shows the essential information. Ex: Calculator,
Mobile , bike.

Encapsulation: in single entity or unit(class , function ) It hides the code and data so that the
data can be protected from the outside . it resolve the naming conflict . Ex: Office bag, vollet,
capsule

Access specifier: Access specifiers(Access Modifier) define how the data member and function
of a class can be accessed.

1Private:

When we declared a methods and data members as Private . It can be be accessed only inside the
class (by default it is private )

2Public:
The classes, methods, or constructors which are declared as Public can be accessed from
anywhere.

3Protected

The methods and data members which are declared as protected are accessible by inside the class
and the child classes of this parent class.

Data Structure : The format of storing data in organized way so we can access data easily and
modified easily. ( Data Structure=Organized data +Allowed operations)

Types of DS:

1Premitive DS: It can hold a single value in memory location. Integer, character boolean etc.

2 Non-Premitive DS: It can hold a multipale values in memory eathercountinueslocation(just like


in array ) or different location(just like linked list) . Ex Arrays ,Stack,Trees , Graphs,Tables. etc.

Types of Nonpremitive DS:

1Linear DS: in Linear DS data is stored in sequence . previous and after data cell is connected
with each other. Ex Arrays,Stack,Queue,Linked List etc.

2Non-Linear DS: in Non- Linear DS data is not stored in sequence .. Ex Trees, Graphs,Tables
etc.
Array (linear DS) is a collection of data that have same type and stores in
contiguous(countinues) memory locations

1D It is used only one subscript(big bracket) to define the elements of Array.

2D It is used two subscript(big bracket) to define the elements of Array.

MultiDimentional It is used more then one subscript(big bracket) to define the elements of
Array.

A stackis linear DS thatfollows a LIFO (Last In First Out) order for storing the elements. A stack
uses one end known as a top for insertion and deletion .Ex The collection of plates placed one
over the other is a real-world example of a stack,

A queue is linear DS that follows a FIFO (First In First Out) order for storing the elements .A
queue uses two ends front and rear for insertion and deletion Ex people standing in a queue to
pay an electricity bill is a real-world example of the queue
A linked list is a linear data structure, in which the data are not stored at contiguous memory
locations. It consists of nodes where each node contains a data field and address of the next node
in the list

Singly Linked List . itis the simplest type of linked list. It has 2 parts . in which first part contain
some data and second part contain address of the next node of the same data type.
Note: tail is null

Doubly Linked List Data are stored in nodes. Each node has 3 parts. First part contain the address
of previous node. Second part containt Data. Third part contain the address of next node
(reference link) to the next node of the same data type.
Note:Head and tail is null

Head tail

singly linked ascircular .It has 2 parts . in which first part contain some data and second part
contain address of the next node of the same data type.

Note: Last node in first part store data and second part store the address of first node.
Doubly Linked List as Circular. Data are stored in nodes. Each node has 3 parts. First part contain
the address of previous node. Second part containt Data. Third part contain the address of next
node (reference link) to the next node of the same data type.

Graph VS tree

A tree is a hierarchical non linear (ds) that consists of collection of nodes. Nodes represent value
and nodes are connected by edges. Loop does not exist

A graph is a non linear data structure that consists of a finite set of nodes (or vertices) and a set of
edges connecting them. Loop exist
Tree

Graph
Aset is a non-linear data structure that stores unique elements of the same type in a sorted order.
Each value is a key, which means that we access each value using the value itself. With arrays,
on the other hand, we access each value by its position in the container (the index). Accordingly,
each value in a set must be unique

You might also like