SlideShare a Scribd company logo
Object Oriented Programming:
Prof Neeraj Bhargava
Vaibhav Khanna
Department of Computer Science
School of Engineering and Systems Sciences
Maharshi Dayanand Saraswati University Ajmer
1-2
Object-Oriented Concepts
• ADTs are usually called classes
• Class instances are called objects
• A class that inherits is a derived class or a
subclass
• The class from which another class inherits is
a parent class or superclass
• Subprograms that define operations on
objects are called methods
1-3
Object-Oriented Concepts (continued)
• Calls to methods are called messages
• The entire collection of methods of an object
is called its message protocol or message
interface
• Messages have two parts--a method name
and the destination object
• In the simplest case, a class inherits all of the
entities of its parent
1-4
Object-Oriented Concepts (continued)
• Inheritance can be complicated by access
controls to encapsulated entities
– A class can hide entities from its subclasses
– A class can hide entities from its clients
– A class can also hide entities for its clients while
allowing its subclasses to see them
• Besides inheriting methods as is, a class can
modify an inherited method
– The new one overrides the inherited one
– The method in the parent is overriden
Object-Oriented Concepts (continued)
• Three ways a class can differ from its parent:
1. The subclass can add variables and/or methods to
those inherited from the parent
2. The subclass can modify the behavior of one or
more of its inherited methods.
3. The parent class can define some of its variables
or methods to have private access, which means
they will not be visible in the subclass
1-5
1-6
Object-Oriented Concepts (continued)
• There are two kinds of variables in a class:
– Class variables - one/class
– Instance variables - one/object
• There are two kinds of methods in a class:
– Class methods – accept messages to the class
– Instance methods – accept messages to objects
• Single vs. Multiple Inheritance
• One disadvantage of inheritance for reuse:
– Creates interdependencies among classes that
complicate maintenance
1-7
Dynamic Binding
• A polymorphic variable can be defined in a class
that is able to reference (or point to) objects of
the class and objects of any of its descendants
• When a class hierarchy includes classes that
override methods and such methods are called
through a polymorphic variable, the binding to
the correct method will be dynamic
• Allows software systems to be more easily
extended during both development and
maintenance
1-8
Dynamic Binding Concepts
• An abstract method is one that does not
include a definition (it only defines a protocol)
• An abstract class is one that includes at least
one virtual method
• An abstract class cannot be instantiated
1-9
Design Issues for OOP Languages
• The Exclusivity of Objects
• Are Subclasses Subtypes?
• Single and Multiple Inheritance
• Object Allocation and Deallocation
• Dynamic and Static Binding
• Nested Classes
• Initialization of Objects
1-10
The Exclusivity of Objects
• Everything is an object
– Advantage - elegance and purity
– Disadvantage - slow operations on simple objects
• Add objects to a complete typing system
– Advantage - fast operations on simple objects
– Disadvantage - results in a confusing type system (two kinds of
entities)
• Include an imperative-style typing system for primitives but
make everything else objects
– Advantage - fast operations on simple objects and a relatively small
typing system
– Disadvantage - still some confusion because of the two type systems
1-11
Are Subclasses Subtypes?
• Does an “is-a” relationship hold between a
parent class object and an object of the
subclass?
– If a derived class is-a parent class, then objects of
the derived class must behave the same as the
parent class object
• A derived class is a subtype if it has an is-a
relationship with its parent class
– Subclass can only add variables and methods and
override inherited methods in “compatible” ways
• Subclasses inherit implementation; subtypes
inherit interface and behavior
1-12
Single and Multiple Inheritance
• Multiple inheritance allows a new class to
inherit from two or more classes
• Disadvantages of multiple inheritance:
– Language and implementation complexity (in part
due to name collisions)
– Potential inefficiency - dynamic binding costs
more with multiple inheritance (but not much)
• Advantage:
– Sometimes it is quite convenient and valuable
1-13
Allocation and DeAllocation of Objects
• From where are objects allocated?
– If they behave line the ADTs, they can be
allocated from anywhere
• Allocated from the run-time stack
• Explicitly create on the heap (via new)
– If they are all heap-dynamic, references can be
uniform thru a pointer or reference variable
• Simplifies assignment - dereferencing can be implicit
– If objects are stack dynamic, there is a problem
with regard to subtypes – object slicing
• Is deallocation explicit or implicit?
1-14
Dynamic and Static Binding
• Should all binding of messages to methods be
dynamic?
– If none are, you lose the advantages of dynamic
binding
– If all are, it is inefficient
• Maybe the design should allow the user to
specify
1-15
Nested Classes
• If a new class is needed by only one class,
there is no reason to define so it can be seen
by other classes
– Can the new class be nested inside the class that
uses it?
– In some cases, the new class is nested inside a
subprogram rather than directly in another class
• Other issues:
– Which facilities of the nesting class should be
visible to the nested class and vice versa
Initialization of Objects
• Are objects initialized to values when they are
created?
– Implicit or explicit initialization
• How are parent class members initialized
when a subclass object is created?
1-16
Assignment
• Explain the Concept of Inheritance in Object
Oriented Programming
• Discuss in detail the Design Issues for OOP
Languages

More Related Content

What's hot (20)

PPT
Abstract class in java
Lovely Professional University
 
PPTX
[OOP - Lec 06] Classes and Objects
Muhammad Hammad Waseem
 
PDF
L2 datatypes and variables
Ravi_Kant_Sahu
 
PPTX
Class Members Access/Visibility Guide (Checklist)
Jayasree Perilakkalam
 
PPTX
Week 2: Getting Your Hands Dirty – Part 2
Jamshid Hashimi
 
PPTX
Inheritance
Siddhesh Palkar
 
PDF
Lecture 10
Debasish Pratihari
 
PDF
Keywords and classes
Ravi_Kant_Sahu
 
DOC
Complete java&j2ee
Shiva Cse
 
PDF
CS4443 - Modern Programming Language I
Dilawar Khan
 
PPTX
Oops concept in Java
Ducat India
 
PPTX
object oriented Programming ppt
Nitesh Dubey
 
PPTX
Basics of java (1)
raj upadhyay
 
PPSX
C#, OOP introduction and examples
agni_agbc
 
PDF
Object Oriented Principles
Sujit Majety
 
PPTX
Java Access Specifier
DeeptiJava
 
PPTX
[OOP - Lec 01] Introduction to OOP
Muhammad Hammad Waseem
 
DOC
116824015 java-j2 ee
homeworkping9
 
PPTX
Access specifiers(modifiers) in java
HrithikShinde
 
Abstract class in java
Lovely Professional University
 
[OOP - Lec 06] Classes and Objects
Muhammad Hammad Waseem
 
L2 datatypes and variables
Ravi_Kant_Sahu
 
Class Members Access/Visibility Guide (Checklist)
Jayasree Perilakkalam
 
Week 2: Getting Your Hands Dirty – Part 2
Jamshid Hashimi
 
Inheritance
Siddhesh Palkar
 
Lecture 10
Debasish Pratihari
 
Keywords and classes
Ravi_Kant_Sahu
 
Complete java&j2ee
Shiva Cse
 
CS4443 - Modern Programming Language I
Dilawar Khan
 
Oops concept in Java
Ducat India
 
object oriented Programming ppt
Nitesh Dubey
 
Basics of java (1)
raj upadhyay
 
C#, OOP introduction and examples
agni_agbc
 
Object Oriented Principles
Sujit Majety
 
Java Access Specifier
DeeptiJava
 
[OOP - Lec 01] Introduction to OOP
Muhammad Hammad Waseem
 
116824015 java-j2 ee
homeworkping9
 
Access specifiers(modifiers) in java
HrithikShinde
 

Similar to Object oriented programming 3 object oriented concepts (20)

PPTX
object oriented programming unit two ppt
isiagnel2
 
PPTX
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
PPTX
Java chapter 5
Abdii Rashid
 
PPTX
Software enginnnering introduction (2).pptx
parmidakhrz02
 
PPTX
CPP Object Oriented Concepts(OOPS).pptx
adityakumardas16
 
PPT
8 oo approach&uml-23_feb
Raj Shah
 
PPTX
Unit II Inheritance ,Interface and Packages.pptx
pranalisonawane8600
 
PPTX
Object oriented programming
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
arthimetic operator,classes,objects,instant
ssuser77162c
 
PDF
Java/J2EE interview Qestions
Arun Vasanth
 
PPTX
) Function overriding, Member Classes Nesting of Classes.pptx
sachinkumar541404
 
PDF
Java programming -Object-Oriented Thinking- Inheritance
Jyothishmathi Institute of Technology and Science Karimnagar
 
PPT
Chap02
Jotham Gadot
 
PDF
Lectupopplkmkmkkpompom-0ookoimmire 2.pdf
rtreduanur247
 
PPTX
Design patterns
Luis Goldster
 
PPT
Polymorphism
Kumar
 
PPT
Topic inheritance
Ankit Kumar
 
PDF
Object oriented programming java inheritance
Fethulmubin
 
object oriented programming unit two ppt
isiagnel2
 
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
Java chapter 5
Abdii Rashid
 
Software enginnnering introduction (2).pptx
parmidakhrz02
 
CPP Object Oriented Concepts(OOPS).pptx
adityakumardas16
 
8 oo approach&uml-23_feb
Raj Shah
 
Unit II Inheritance ,Interface and Packages.pptx
pranalisonawane8600
 
arthimetic operator,classes,objects,instant
ssuser77162c
 
Java/J2EE interview Qestions
Arun Vasanth
 
) Function overriding, Member Classes Nesting of Classes.pptx
sachinkumar541404
 
Java programming -Object-Oriented Thinking- Inheritance
Jyothishmathi Institute of Technology and Science Karimnagar
 
Chap02
Jotham Gadot
 
Lectupopplkmkmkkpompom-0ookoimmire 2.pdf
rtreduanur247
 
Design patterns
Luis Goldster
 
Polymorphism
Kumar
 
Topic inheritance
Ankit Kumar
 
Object oriented programming java inheritance
Fethulmubin
 
Ad

More from Vaibhav Khanna (20)

PPTX
Information and network security 47 authentication applications
Vaibhav Khanna
 
PPTX
Information and network security 46 digital signature algorithm
Vaibhav Khanna
 
PPTX
Information and network security 45 digital signature standard
Vaibhav Khanna
 
PPTX
Information and network security 44 direct digital signatures
Vaibhav Khanna
 
PPTX
Information and network security 43 digital signatures
Vaibhav Khanna
 
PPTX
Information and network security 42 security of message authentication code
Vaibhav Khanna
 
PPTX
Information and network security 41 message authentication code
Vaibhav Khanna
 
PPTX
Information and network security 40 sha3 secure hash algorithm
Vaibhav Khanna
 
PPTX
Information and network security 39 secure hash algorithm
Vaibhav Khanna
 
PPTX
Information and network security 38 birthday attacks and security of hash fun...
Vaibhav Khanna
 
PPTX
Information and network security 37 hash functions and message authentication
Vaibhav Khanna
 
PPTX
Information and network security 35 the chinese remainder theorem
Vaibhav Khanna
 
PPTX
Information and network security 34 primality
Vaibhav Khanna
 
PPTX
Information and network security 33 rsa algorithm
Vaibhav Khanna
 
PPTX
Information and network security 32 principles of public key cryptosystems
Vaibhav Khanna
 
PPTX
Information and network security 31 public key cryptography
Vaibhav Khanna
 
PPTX
Information and network security 30 random numbers
Vaibhav Khanna
 
PPTX
Information and network security 29 international data encryption algorithm
Vaibhav Khanna
 
PPTX
Information and network security 28 blowfish
Vaibhav Khanna
 
PPTX
Information and network security 27 triple des
Vaibhav Khanna
 
Information and network security 47 authentication applications
Vaibhav Khanna
 
Information and network security 46 digital signature algorithm
Vaibhav Khanna
 
Information and network security 45 digital signature standard
Vaibhav Khanna
 
Information and network security 44 direct digital signatures
Vaibhav Khanna
 
Information and network security 43 digital signatures
Vaibhav Khanna
 
Information and network security 42 security of message authentication code
Vaibhav Khanna
 
Information and network security 41 message authentication code
Vaibhav Khanna
 
Information and network security 40 sha3 secure hash algorithm
Vaibhav Khanna
 
Information and network security 39 secure hash algorithm
Vaibhav Khanna
 
Information and network security 38 birthday attacks and security of hash fun...
Vaibhav Khanna
 
Information and network security 37 hash functions and message authentication
Vaibhav Khanna
 
Information and network security 35 the chinese remainder theorem
Vaibhav Khanna
 
Information and network security 34 primality
Vaibhav Khanna
 
Information and network security 33 rsa algorithm
Vaibhav Khanna
 
Information and network security 32 principles of public key cryptosystems
Vaibhav Khanna
 
Information and network security 31 public key cryptography
Vaibhav Khanna
 
Information and network security 30 random numbers
Vaibhav Khanna
 
Information and network security 29 international data encryption algorithm
Vaibhav Khanna
 
Information and network security 28 blowfish
Vaibhav Khanna
 
Information and network security 27 triple des
Vaibhav Khanna
 
Ad

Recently uploaded (20)

PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Tally software_Introduction_Presentation
AditiBansal54083
 

Object oriented programming 3 object oriented concepts

  • 1. Object Oriented Programming: Prof Neeraj Bhargava Vaibhav Khanna Department of Computer Science School of Engineering and Systems Sciences Maharshi Dayanand Saraswati University Ajmer
  • 2. 1-2 Object-Oriented Concepts • ADTs are usually called classes • Class instances are called objects • A class that inherits is a derived class or a subclass • The class from which another class inherits is a parent class or superclass • Subprograms that define operations on objects are called methods
  • 3. 1-3 Object-Oriented Concepts (continued) • Calls to methods are called messages • The entire collection of methods of an object is called its message protocol or message interface • Messages have two parts--a method name and the destination object • In the simplest case, a class inherits all of the entities of its parent
  • 4. 1-4 Object-Oriented Concepts (continued) • Inheritance can be complicated by access controls to encapsulated entities – A class can hide entities from its subclasses – A class can hide entities from its clients – A class can also hide entities for its clients while allowing its subclasses to see them • Besides inheriting methods as is, a class can modify an inherited method – The new one overrides the inherited one – The method in the parent is overriden
  • 5. Object-Oriented Concepts (continued) • Three ways a class can differ from its parent: 1. The subclass can add variables and/or methods to those inherited from the parent 2. The subclass can modify the behavior of one or more of its inherited methods. 3. The parent class can define some of its variables or methods to have private access, which means they will not be visible in the subclass 1-5
  • 6. 1-6 Object-Oriented Concepts (continued) • There are two kinds of variables in a class: – Class variables - one/class – Instance variables - one/object • There are two kinds of methods in a class: – Class methods – accept messages to the class – Instance methods – accept messages to objects • Single vs. Multiple Inheritance • One disadvantage of inheritance for reuse: – Creates interdependencies among classes that complicate maintenance
  • 7. 1-7 Dynamic Binding • A polymorphic variable can be defined in a class that is able to reference (or point to) objects of the class and objects of any of its descendants • When a class hierarchy includes classes that override methods and such methods are called through a polymorphic variable, the binding to the correct method will be dynamic • Allows software systems to be more easily extended during both development and maintenance
  • 8. 1-8 Dynamic Binding Concepts • An abstract method is one that does not include a definition (it only defines a protocol) • An abstract class is one that includes at least one virtual method • An abstract class cannot be instantiated
  • 9. 1-9 Design Issues for OOP Languages • The Exclusivity of Objects • Are Subclasses Subtypes? • Single and Multiple Inheritance • Object Allocation and Deallocation • Dynamic and Static Binding • Nested Classes • Initialization of Objects
  • 10. 1-10 The Exclusivity of Objects • Everything is an object – Advantage - elegance and purity – Disadvantage - slow operations on simple objects • Add objects to a complete typing system – Advantage - fast operations on simple objects – Disadvantage - results in a confusing type system (two kinds of entities) • Include an imperative-style typing system for primitives but make everything else objects – Advantage - fast operations on simple objects and a relatively small typing system – Disadvantage - still some confusion because of the two type systems
  • 11. 1-11 Are Subclasses Subtypes? • Does an “is-a” relationship hold between a parent class object and an object of the subclass? – If a derived class is-a parent class, then objects of the derived class must behave the same as the parent class object • A derived class is a subtype if it has an is-a relationship with its parent class – Subclass can only add variables and methods and override inherited methods in “compatible” ways • Subclasses inherit implementation; subtypes inherit interface and behavior
  • 12. 1-12 Single and Multiple Inheritance • Multiple inheritance allows a new class to inherit from two or more classes • Disadvantages of multiple inheritance: – Language and implementation complexity (in part due to name collisions) – Potential inefficiency - dynamic binding costs more with multiple inheritance (but not much) • Advantage: – Sometimes it is quite convenient and valuable
  • 13. 1-13 Allocation and DeAllocation of Objects • From where are objects allocated? – If they behave line the ADTs, they can be allocated from anywhere • Allocated from the run-time stack • Explicitly create on the heap (via new) – If they are all heap-dynamic, references can be uniform thru a pointer or reference variable • Simplifies assignment - dereferencing can be implicit – If objects are stack dynamic, there is a problem with regard to subtypes – object slicing • Is deallocation explicit or implicit?
  • 14. 1-14 Dynamic and Static Binding • Should all binding of messages to methods be dynamic? – If none are, you lose the advantages of dynamic binding – If all are, it is inefficient • Maybe the design should allow the user to specify
  • 15. 1-15 Nested Classes • If a new class is needed by only one class, there is no reason to define so it can be seen by other classes – Can the new class be nested inside the class that uses it? – In some cases, the new class is nested inside a subprogram rather than directly in another class • Other issues: – Which facilities of the nesting class should be visible to the nested class and vice versa
  • 16. Initialization of Objects • Are objects initialized to values when they are created? – Implicit or explicit initialization • How are parent class members initialized when a subclass object is created? 1-16
  • 17. Assignment • Explain the Concept of Inheritance in Object Oriented Programming • Discuss in detail the Design Issues for OOP Languages