Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 26

OOPS – OBJECT ORIENTED PARADIGMS

BASIC TERMINOLOGIES OF OOPS

Class

Objects

Methods

Constructors
CLASS

• Class is an abstract as well user defined data type.

• The primary purpose of class is to store data and


information.

• The members of class defines the class.

• Class cannot be seen to real world but an object can be seen.

• A class is basically an object constructor or a blueprint for an


object.
CREATING AN INSTANCE OF THE CLASS

A class needs to be
instantiated if we want A class can be
to use the class instantiated by calling
attributes in another the class using the
class or method. class name.
OBJECTS
OBJECTS

Objects are an encapsulation of variables and functions into a single


entity.

Objects get their variables and functions from classes.

The implementation of class is an object

The class is not visible to the outside world but object does
OBJECT CREATION using __init__ method
The __init__ method is similar to constructors in C++ and Java. It is run as soon as an object
of a class is instantiated. The method is useful to do any initialization you want to do with
your object.

CONSTRUCTOR

METHOD

OBJECT
ACCESSING METHOD
USING OBJECT
OOPS CONEPTS

Data
Inheritance Polymorphism
Encapsulation

Exception
Data Abstraction
Handling
INHERITANCE
INHERITANCE
• Inheritance allows us to define a class that inherits all the methods and properties from
another class.

• Parent class is the class being inherited from, also called base class.

• Child class is the class that inherits from another class, also called derived class.

Syntax of Inheritance
• class DerivedClassName(BaseClassName):
    Statement-1
    Statement-1
    ....
    ....
    ....
    Statement-n
TYPES OF INHERITANCE
SINGLE INHERITANCE
When a child class inherits from one parent class, it is single inheritance.
MULTIPLE INHERITANCE
When a child class inherits from more than one parent class, it is multiple inheritance.
MULTI LEVEL INHERITANCE
When a child class inherits from other child class , it is multi-level inheritance.
HIERARCHICAL INHERITANCE
Hierarchical inheritance involves multiple inheritance from the same base or parent class.
HYBRID INHERITANCE
Hybrid inheritance involves multiple inheritance taking place in single program.
SUPER METHOD
POLYMORPHISM
POLYMORPHISM

Polymorphism Means a Many-form, Its derived from 2 Greek


words: First word “poly” means many and another “morphs”
means forms. 

Existence of one function in many forms

A Polymorphism possible when classes are related to each


other by is-a Relationship (Inheritance).
CODE ON POLYMORPHISM
METHOD OVERRIDING
• Redefining certain methods and attributes specifically to fit the child class, which is
known as Method Overriding.

• Polymorphism allows us to access these overridden methods and attributes that have
the same name as the parent class.
Problem statement 1

A class defines a blueprint for an object. We use the same syntax to declare objects of a class as we use
to declare variables of other basic types. For example:

Box box1; // Declares variable box1 of type Box


Box box2; // Declare variable box2 of type Box
Kristen is a contender for valedictorian of her high school. She wants to know how many students (if
any) have scored higher than her in the exams given during this semester.

Create a class named Student with the following specifications:

An instance variable named scores to hold a student’s 5 exam scores.


A void input() function that reads 5 integers and saves them to scores .
An int calculateTotalScore() function that returns the sum of the student's scores.
Problem statement 1

Input Format
Most of the input is handled for you by the locked code in the editor.

In the void Student::input() function, you must read 5 scores from stdin and save them to your scores
instance variable.

Constraints
1 <= n <= 100
0<= examscore <= 50
Problem statement 1

Output Format

In the int Student::calculateTotalScore() function, you must return the student's total grade (the sum of
the values in scores ).

The locked code in the editor will determine how many scores are larger than Kristen's and print that
number to the console.
Problem statement 1

Sample Input
The first line contains , the number of students in Kristen's class. The n subsequent lines contain each
student’s 5 exam grades for this semester.

3
30 40 45 10 10
40 40 40 10 10
50 20 30 10 10
Sample Output: 1
Explanation
Kristen's grades are on the first line of grades. Only 1 student scored higher than her.
Problem statement 2

Write a Python class to find validity of a string of parentheses, '(', ')', '{', '}', '[' and ']. These brackets
must be closed in the correct order,
Example : here, "()" and "()[]{}" are valid but "[)", "({[)]" and "{{{" are invalid.

Use function is_valid_parenthese() that takes a string parameter str1.


Output the value True or False if string of parentheses is valid or not resp.

You might also like