[go: up one dir, main page]

0% found this document useful (0 votes)
20 views28 pages

OOP Concepts

Uploaded by

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

OOP Concepts

Uploaded by

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

HEXAWARE TRAINING- 2022

OBJECT ORIENTED PROGRAMMING


CONCEPTS
By Dr V Venkateswara Rao
Object-oriented programming –
As the name suggests , it uses objects in programming. Object-
oriented programming aims to implement real-world entities like
inheritance, hiding, polymorphism, etc in programming. The main
aim of OOP is to bind together the data and the functions that
operate on them so that no other part of the code can access this
data except that function.

Elements of OOP(Building blocks of OOP):


Classes
Objects
Data(Attributes)
Functions() or Methods (code)
Four Principles of OOP
The four pillars of object oriented programming are:
Inheritance: child classes inherit data and behaviors from parent
class
Encapsulation: containing information in an object, exposing only
selected information
Abstraction: only exposing high level public methods for accessing
an object
Polymorphism: many methods can do the same task
Characteristics of an Object Oriented Programming language
classes are essentially user defined data types. Classes are where we create a
blueprint for the structure of methods and attributes. Individual objects are
instantiated, or created from this blueprint.
Classes contain fields for attributes, and methods for behaviors.
A Class is a user-defined data-type which has data members and member functions.
Data members are the data variables and member functions are the functions used to
manipulate these variables and together these data members and member functions
define the properties and behaviour of the objects in a Class.

Encapsulation: In normal terms, Encapsulation is defined as wrapping up of data


and information under a single unit. In Object-Oriented Programming,
Encapsulation is defined as binding together the data and the functions that
manipulate them.
Objects are instances of classes created with specific data.
Any entity that has state and behavior is known as an object. Any entity that has state
and behavior is known as an object.
State means Memory Allocation
Behaviour means code that executes
Encapsulation
Binding (or wrapping) code and data together into a single unit is known as
encapsulation

Encapsulation: In normal terms, Encapsulation is defined as wrapping up of data and


information under a single unit. In Object-Oriented Programming, Encapsulation is
defined as binding together the data and the functions that manipulate them.

Encapsulation is placing the data and the functions that work on that data in the
same place. While working with procedural languages, it is not always clear which
functions work on which variables but object-oriented programming provides you
framework to place the data and the relevant functions together in the same object.
Abstraction
Abstraction refers to showing only the essential features of the application and hiding
the details. In C++, classes can provide methods to the outside world to access & use
the data variables, keeping the variables hidden from direct access, or classes can even
declare everything accessible to everyone, or maybe just to the classes inheriting it.
This can be done using access specifiers.

Abstraction is a process of hiding the implementation details from the user, only the
functionality will be provided to the user. In other words, the user will have the
information on what the object does instead of how it does it.
In Java, abstraction is achieved using Abstract classes and interfaces.

The benefits of encapsulation are summarized here:


Adds security: Only public methods and attributes are accessible from the outside
Protects against common mistakes: Only public fields & methods accessible, so
developers don’t accidentally change something dangerous
Protects IP: Code is hidden in a class, only public methods are accessible by the outside
developers
Supportable: Most code undergoes updates and improvements
Hides complexity: No one can see what’s behind the object’s curtain!
Inheritance
Inheritance can be defined as the process where one (parent/super) class acquires
the properties (methods and fields) of another (child/sub). With the use of
inheritance, the information is made manageable in a hierarchical order.
Polymorphism
Polymorphism is the ability of an object to perform different actions (or, exhibit
different behaviors) based on the context.
Message Passing: Objects communicate with one another by sending and receiving
information to each other. A message for an object is a request for execution of a
procedure and therefore will invoke a function in the receiving object that generates
the desired results. Message passing involves specifying the name of the object, the
name of the function and the information to be sent.
Dynamic Binding
Dynamic binding also called dynamic dispatch is the process of linking procedure call to a
specific sequence of code (method) at run-time. It means that the code to be executed for a
specific procedure call is not known until run-time. Dynamic binding is also known as late
binding or run-time binding.

Dynamic binding is an object oriented programming concept and it is related with


polymorphism and inheritance.

Dynamic binding definition


Dynamic binding(dispatch) means that a block of code executed with reference to a
procedure(method) call is determined at run time.
Dynamic dispatch is generally used when multiple classes contain different implementations
of the same method. It provides a mechanism for selecting the function to be executed
from various function alternatives at the run-time. In C++, virtual functions are used to
implement dynamic binding.
Which was the first purely object oriented programming
language developed?
a) Java
b) C++
c) SmallTalk
d) Kotlin

Answer: c
Which of the following best defines a class?
a) Parent of an object
b) Instance of an object
c) Blueprint of an object
d) Scope of an object
Answer: c
class is blue print or template for an object or structure of object
Who invented OOP?
a) Alan Kay
b) Andrea Ferro
c) Dennis Ritchie
d) Adele Goldberg

Answer: a
Explanation: Alan Kay invented OOP, Andrea Ferro was a part of
SmallTalk Development.
Dennis invented C++ and Adele Goldberg was in team to develop
SmallTalk but Alan actually had got rewarded for OOP.
What is the additional feature in classes that was not in structures?
a) Data members
b) Member functions
c) Static data allowed
d) Public access specifier
Answer: b
Explanation: Member functions are allowed inside a class but were
not present in structure concept. Data members, static data and
public access specifiers were present in structures too.
Which is not feature of OOP in general definitions?
a) Code reusability
b) Modularity
c) Duplicate/Redundant data
d) Efficient Code
Answer: c
Explanation: Duplicate/Redundant data is dependent on
programmer and hence can’t be guaranteed by OOP. Code
reusability is done using inheritance. Modularity is supported by
using different code files and classes. Codes are more efficient
because of features of OOP.
Which Feature of OOP illustrated the code reusability?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Inheritance
Answer: d
Explanation: Using inheritance we can reuse the code already
written and also can avoid creation of many new functions or
variables, as that can be done one time and be reused, using
classes.
Which language does not support all 4 types of inheritance?
a) C++
b) Java
c) Kotlin
d) Small Talk
Answer: b
Explanation: Java doesn’t support all 4 types of inheritance.
It doesn’t support multiple inheritance. But the multiple
inheritance can be implemented using interfaces in Java.
How many classes can be defined in a single program?
a) Only 1
b) Only 100
c) Only 999
d) As many as you want
Answer: d
Explanation: Any number of classes can be defined inside a
program, provided that their names are different. In java, if
public class is present then it must have the same name as
that of file.
Which of the two features match each other?
a) Inheritance and Encapsulation
b) Encapsulation and Polymorphism
c) Encapsulation and Abstraction
d) Abstraction and Polymorphism
Answer: c
Explanation: Encapsulation and Abstraction are similar features.
Encapsulation is actually binding all the properties in a single class
or we can say hiding all the features of object inside a class. And
Abstraction is hiding unwanted data (for user) and showing only
the data required by the user of program.
Which of following is shared structure of a set of similar
objects
Encapsulation
A Class
Inheritance
None of Above

A Class is shared structure of a set of similar objects


In oops public, private & protected are
Classes
Access Modifiers
Interfaces
Method signature

Public, private & protected are Access Modifiers in OOPs


A private member of a class is visible to
every where
in sub class
members to same package
only members of same class

A private member of a class is visible to only members of same class


Which of the following is not related to OOPS?
Class and Object
Constructor and Destructor
Structure and Union
Inheritance and Polymorphism

Structure and Union is not related to OOPS


Which one of the following are essential features of an object-oriented
programming language?
(i) Abstraction and encapsulation
(ii) Strictly-typedness
(iii) Type-safe property coupled with sub-type rule
(iv) Polymorphism in the presence of inheritance

A (i) and (ii) only


B (i) and (iv) only
C (i), (ii) and (iv) only
D (i), (iii) and (iv) only
Ans: B
Which of the following is associated with objects?
A State
B Behaviour
C Identity
D All of the above
Ans: D
The feature in object-oriented programming that allows the
same operation to be carried out differently, depending on
the object, is:
A Inheritance
B Polymorphism
C Over functioning
D Overriding
Ans: B
Which of the following concepts means determining at runtime what method to
invoke?

A. Data hiding
B. Dynamic Typing
C. Dynamic binding
D. Dynamic loading
Answer: Option C

You might also like