SlideShare a Scribd company logo
Object Oriented
Programming
Interview Preparation
Keet Malin Sugathadasa
Undergraduate
Department of Computer Science and Engineering
University of Moratuwa
Agenda
● Objects (Instances)
● Classes
● Advantages of OOP
● Disadvantages of OOP
● Let’s Design an OOP Solution
● OOP Concepts
● UML - Unified Modelling Language
● UML Syntax
● Associations
● Inheritance
● Cohesion and Coupling
Objects (Instances)
An Object can be used to effectively represent real world entities
● Object has
○ States (descriptive characteristics)
■ Simple Attributes- Primitive data types
■ Complex Attributes - Contains collections
○ Behaviours ( what it can do)
Example
● Keet’s Bank Account
○ State: Account number, Available balance
○ Behaviour: Make deposits, Withdraw
Classes
● An object is defined by a class
Advantages of OOP
● Code Reusing and Recycling
○ Saves development time and cost
● Encapsulation
○ Once object is created, knowledge of its implementation is not necessary for use.
● Design Benefits
○ Easy to understand. Large programs get more and more complex, but with OOP, designs can
be made with less flaws
● Software Maintenance
○ Programs are not disposable. An OOP is much easier to modify and maintain than a non-OOP
Disadvantages of OOP
● Size
○ OOPs are much larger than other programs
● Effort
○ OOPs require a lot of work and planning to develop
● Speed
○ OOPs are slower than other programs (Partially because of their size)
Object Oriented Problem Solving Approach
1. Identify the Problem
a. Carefully read the given problem and highlight the important points
2. Identify the Objects
a. Identify the main objects. Sometime two entities can be selected as one, but sometimes, it
might be better to have two instead of one complex one.
3. Identify the messages to be sent to other objects
a. Identify what kind of interactions happen between objects in classes
4. Create a sequence of messages to the objects - to solve the problem
a. Find a pattern to solve the final problem by interacting with different objects.
Let’s Design an OOP Solution
You need to create a Wedding Management System. Each wedding has a bride, a
groom, flower decorator, food provider, location etc. Each bride and groom has
their own parents and friends.
Find a way to model this problem into an OOP solution.
Just identifying the objects and the required interactions between them is
sufficient. Represent the interactions by simple arrows.
Overview of OOP
OOP Concepts
● Abstraction
○ Allows us to consider the important high level details
● Encapsulation
○ Allows us to consider what the program does and how it operates it. Without reading the
technical details of how it actually works
● Inheritance
○ Generalization and Specialization. Specialized objects can automatically inherit all the
characteristics of the more generalized objects.
● Polymorphism
○ Is the ability to interact with an object as its generalized category, regardless of its more
specialized category.
UML - Unified Modelling Language
● Class Diagrams
○ Classes show what the objects consists of and the methods
● Object Diagrams
○ Objects in the system and how they interact and the values in that object at a given state in time
● Sequence Diagrams
○ shows object interactions arranged in time sequence. How objects will interact to support one
specific function
● Package Diagrams
○ Packages and dependencies between packages
Class Consists of
● A unique Name
○ Conventionally starting with an Uppercase Letter
● A list of Attributes (Mostly Private)
○ Int, double, boolean, String, Complex Attributes
● A list of Methods (Mostly Public)
○ Unique method names starting with a Lowercase letter
Visibility Modifiers (Access Modifiers)
+ for public access
- for private access
UML allows us to suppress any information we do not wish to highlight in our
diagrams
UML Syntax
● Attributes
○ <visibility> <name> : <type> <multiplicity>
■ Eg: + custRef : int [1] → a public attribute custRef is a single int value
● Methods
○ <visibility> <name> ( <parameter 1> : <type 1> , …….) : <Return Type>
■ Eg: + addName (newName : String) : Boolean
Relationships Between Classes
● Some Class attributes can be complex
○ Can include some other class object as attributes
■ Eg: Teacher class has attribute → list of Students
○ String data type is a complex data type
■ Since it is part of the Java platform, it is implied that String is a primitive data type
Example
● ‘n’ → exactly n
● ‘*’ → zero or more
● ‘m..n; → between m and n
Types of Association
● Dependency A --------------------------> B
● Simple Association A B
● Bidirectional Association A B
● Aggregation A B
● Composition A B
Dependency
Class A in some way uses facilities defined by Class B. Changes to class B may
affect class A. There are 3 ways in which dependencies can occur
● Class A has a method, which passes as a parameter object of Class B
● Class A uses a local variable of Class B
● Class A calls static methods in Class B
Simple Association
Class A uses objects of Class B. Typically Class A has an attribute of Class B.
Navigability is from A to B.
● Class A objects can access Class B objects with which it is associated.
○ The reverse is not true.
Eg: Teacher wants to maintain a list of Students. So navigability is from Teacher to
Student. So Teacher object can access Student objects. But student objects do not
necessarily need access to teacher objects.
Bidirectional Association
This is when Class A and Class B has a two way association. Each refers to the
other class. Navigability is from A to B and B to A.
Navigability from A to B means
● Class A object can access Class B objects
● Objects of Class A “Has a” Class A
● This implies reference from A to B
Eg:
Between a “Degree” and “Student”. Given a degree, we may need to know which
students are studying on that degree. Alternatively, given a student, we may wish
to know the degree they are studying.
Aggregation
Aggregation denotes a situation where object(s) of Class B “Belongs to” Class B.
Aggregation also mentions that Objects of Class B, retain an existence
independent of Class A.
Eg:
We can think of tyres belonging to a car. Tyres “Belong To” Cars. But if our context
relates to a tyre shop or something, then Tyres can exist alone, in a garage as well.
Composition
● Composition is similar to aggregation, but implies a much stronger relationship.
● Class B objects are an integral part of Class A. In general, objects of class B
never exist other than as part of Class A. Both have the same lifetime.
Eg:
Between points, lines and shapes as elements of a picture. These objects can only
exist as part of a picture, and if the picture is deleted, they are also deleted.
Inheritance
Class A Class B
Class A inherits both implementation and interface of Class B.
This is how specialization and generalization works. Specialized classes can inherit
from generalized classes.
Interfaces
Class A Class B
● With interface inheritance, Class A will inherit only the interface of Class B.
● Class B contains only method headers
● Class A has to implement all methods defined in Class B
Cohesion
● Cohesion describes how closely all routines in a class or all the code in a
routing support a central purpose.
● Cohesion must be Strong.
● Classes must contain a strongly related functionality and aim for single
purpose
● Cohesion is an important tool for managing complexities
Coupling
● Coupling describes how tightly a class or routine is related to other classes or
routines.
● Coupling must be kept Loose.
○ Modules must depend little on each other
○ One module can be replaced easily without causing trouble
○ A module can be easily used by other modules
● Two types of Coupling
○ Tight Coupling
○ Loose Coupling

More Related Content

PPTX
OOP interview questions & answers.
Questpond
 
PPTX
Angular 5 presentation for beginners
Imran Qasim
 
PDF
ORM: Object-relational mapping
Abhilash M A
 
PPT
Oop Presentation
Ghaffar Khan
 
PPTX
Angular Basics.pptx
AshokKumar616995
 
PPTX
OOPs in Java
Ranjith Sekar
 
PPTX
Object oriented programming
Amit Soni (CTFL)
 
OOP interview questions & answers.
Questpond
 
Angular 5 presentation for beginners
Imran Qasim
 
ORM: Object-relational mapping
Abhilash M A
 
Oop Presentation
Ghaffar Khan
 
Angular Basics.pptx
AshokKumar616995
 
OOPs in Java
Ranjith Sekar
 
Object oriented programming
Amit Soni (CTFL)
 

What's hot (20)

PPTX
What is Angular?
Albiorix Technology
 
PPT
ASP.NET Session 6
Sisir Ghosh
 
PPTX
concept of oops
prince sharma
 
PPT
Ch2 Liang
Dorothea Chaffin
 
PDF
GraphQL: Enabling a new generation of API developer tools
Sashko Stubailo
 
PPT
Oops concept in c#
ANURAG SINGH
 
PDF
Concepts of OOPs
Essay Corp
 
PPTX
Object oriented programming
Sandeep Kumar Singh
 
PPTX
Introduction to OOP concepts
Ahmed Farag
 
PPTX
ASP.NET Web API
habib_786
 
PPT
Oauth2.0
Yasmine Gaber
 
PDF
Solid principles of oo design
Confiz
 
PDF
DI Container를 이용하여 레거시와 모듈화를 동시에 잡기
정민 안
 
PDF
Modern Security with OAuth 2.0 and JWT and Spring by Dmitry Buzdin
Java User Group Latvia
 
PPTX
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
PPTX
Angular overview
Thanvilahari
 
PDF
Lecture 4-oop class diagram
ktuonlinenotes
 
PPTX
Spring framework-tutorial
vinayiqbusiness
 
PPTX
Ch 7 data binding
Madhuri Kavade
 
PPT
C sharp
Satish Verma
 
What is Angular?
Albiorix Technology
 
ASP.NET Session 6
Sisir Ghosh
 
concept of oops
prince sharma
 
Ch2 Liang
Dorothea Chaffin
 
GraphQL: Enabling a new generation of API developer tools
Sashko Stubailo
 
Oops concept in c#
ANURAG SINGH
 
Concepts of OOPs
Essay Corp
 
Object oriented programming
Sandeep Kumar Singh
 
Introduction to OOP concepts
Ahmed Farag
 
ASP.NET Web API
habib_786
 
Oauth2.0
Yasmine Gaber
 
Solid principles of oo design
Confiz
 
DI Container를 이용하여 레거시와 모듈화를 동시에 잡기
정민 안
 
Modern Security with OAuth 2.0 and JWT and Spring by Dmitry Buzdin
Java User Group Latvia
 
ASP.NET Core MVC + Web API with Overview
Shahed Chowdhuri
 
Angular overview
Thanvilahari
 
Lecture 4-oop class diagram
ktuonlinenotes
 
Spring framework-tutorial
vinayiqbusiness
 
Ch 7 data binding
Madhuri Kavade
 
C sharp
Satish Verma
 
Ad

Similar to Object oriented programming interview questions (20)

PPT
Object oriented programming in C++ programming language
SurindraKumar
 
PPT
Object oriented programming language in software engineering
SurindraKumar
 
PPT
Introduction to software engineering in data science.ppt
SurindraKumar
 
PPT
UML DIAGRAMS FOR IST SEMISTER OF BTECH STUDENTS
sagjyothi123
 
PPT
Basics of uml
Naga Muruga
 
PPTX
introofUML.pptx
RojaPogul1
 
PPTX
Unified Modeling Language and Examples .pptx
abinaya707644
 
PPTX
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
PPTX
Object Oriented Principles
Emprovise
 
PPT
Object Oriented Relationships
Taher Barodawala
 
PPTX
Concepts of oops
Sourabrata Mukherjee
 
PPT
Object Oriented Design
Aravinth NSP
 
PPT
Object Oriented Design
Sudarsun Santhiappan
 
PPTX
SAD02 - Object Orientation
Michael Heron
 
PDF
OBJECT ORIENTED CONCEPTS,UML DIAGRAMS,DFD
smithaps4
 
PPSX
DISE - OOAD Using UML
Rasan Samarasinghe
 
PPTX
1. introduction to uml
PRABU M
 
PPTX
Intro to oop.pptx
UmerUmer25
 
PPT
31 uml
sshashib
 
PDF
unit-1modellingconceptsclassmodeling-140929182538-phpapp01.pdf
RojaPogul1
 
Object oriented programming in C++ programming language
SurindraKumar
 
Object oriented programming language in software engineering
SurindraKumar
 
Introduction to software engineering in data science.ppt
SurindraKumar
 
UML DIAGRAMS FOR IST SEMISTER OF BTECH STUDENTS
sagjyothi123
 
Basics of uml
Naga Muruga
 
introofUML.pptx
RojaPogul1
 
Unified Modeling Language and Examples .pptx
abinaya707644
 
SKILLWISE - OOPS CONCEPT
Skillwise Group
 
Object Oriented Principles
Emprovise
 
Object Oriented Relationships
Taher Barodawala
 
Concepts of oops
Sourabrata Mukherjee
 
Object Oriented Design
Aravinth NSP
 
Object Oriented Design
Sudarsun Santhiappan
 
SAD02 - Object Orientation
Michael Heron
 
OBJECT ORIENTED CONCEPTS,UML DIAGRAMS,DFD
smithaps4
 
DISE - OOAD Using UML
Rasan Samarasinghe
 
1. introduction to uml
PRABU M
 
Intro to oop.pptx
UmerUmer25
 
31 uml
sshashib
 
unit-1modellingconceptsclassmodeling-140929182538-phpapp01.pdf
RojaPogul1
 
Ad

More from Keet Sugathadasa (9)

PDF
Chaos Engineering - The Art of Breaking Things in Production
Keet Sugathadasa
 
PDF
Site Reliability Engineering (SRE) - Tech Talk by Keet Sugathadasa
Keet Sugathadasa
 
PDF
Human Computer Interaction - Facebook Messenger
Keet Sugathadasa
 
PDF
Cyber Security and Cloud Computing
Keet Sugathadasa
 
PPTX
How to compete in hackathons
Keet Sugathadasa
 
PDF
Quality Engineering - When to Stop Testing
Keet Sugathadasa
 
PDF
Training Report WSO2 internship
Keet Sugathadasa
 
PDF
Interview Facing Workshop
Keet Sugathadasa
 
PPTX
Revolutionizing digital authentication with gsma mobile connect
Keet Sugathadasa
 
Chaos Engineering - The Art of Breaking Things in Production
Keet Sugathadasa
 
Site Reliability Engineering (SRE) - Tech Talk by Keet Sugathadasa
Keet Sugathadasa
 
Human Computer Interaction - Facebook Messenger
Keet Sugathadasa
 
Cyber Security and Cloud Computing
Keet Sugathadasa
 
How to compete in hackathons
Keet Sugathadasa
 
Quality Engineering - When to Stop Testing
Keet Sugathadasa
 
Training Report WSO2 internship
Keet Sugathadasa
 
Interview Facing Workshop
Keet Sugathadasa
 
Revolutionizing digital authentication with gsma mobile connect
Keet Sugathadasa
 

Recently uploaded (20)

PDF
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
PDF
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
PDF
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
PDF
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
PDF
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
PPTX
Smart Panchayat Raj e-Governance App.pptx
Rohitnikam33
 
PDF
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
PDF
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
PDF
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
PDF
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
PPTX
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
PDF
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PPTX
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
PPTX
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
PPTX
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
PPT
Activate_Methodology_Summary presentatio
annapureddyn
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PDF
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
PDF
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 
Why Use Open Source Reporting Tools for Business Intelligence.pdf
Varsha Nayak
 
Wondershare Filmora 14.5.20.12999 Crack Full New Version 2025
gsgssg2211
 
Micromaid: A simple Mermaid-like chart generator for Pharo
ESUG
 
Teaching Reproducibility and Embracing Variability: From Floating-Point Exper...
University of Rennes, INSA Rennes, Inria/IRISA, CNRS
 
ShowUs: Pharo Stream Deck (ESUG 2025, Gdansk)
ESUG
 
Smart Panchayat Raj e-Governance App.pptx
Rohitnikam33
 
Jenkins: An open-source automation server powering CI/CD Automation
SaikatBasu37
 
Build Multi-agent using Agent Development Kit
FadyIbrahim23
 
Appium Automation Testing Tutorial PDF: Learn Mobile Testing in 7 Days
jamescantor38
 
advancepresentationskillshdhdhhdhdhdhhfhf
jasmenrojas249
 
classification of computer and basic part of digital computer
ravisinghrajpurohit3
 
Become an Agentblazer Champion Challenge Kickoff
Dele Amefo
 
Exploring AI Agents in Process Industries
amoreira6
 
Contractor Management Platform and Software Solution for Compliance
SHEQ Network Limited
 
Can You Build Dashboards Using Open Source Visualization Tool.pptx
Varsha Nayak
 
Maximizing Revenue with Marketo Measure: A Deep Dive into Multi-Touch Attribu...
bbedford2
 
Activate_Methodology_Summary presentatio
annapureddyn
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
49784907924775488180_LRN2959_Data_Pump_23ai.pdf
Abilash868456
 
What to consider before purchasing Microsoft 365 Business Premium_PDF.pdf
Q-Advise
 

Object oriented programming interview questions

  • 1. Object Oriented Programming Interview Preparation Keet Malin Sugathadasa Undergraduate Department of Computer Science and Engineering University of Moratuwa
  • 2. Agenda ● Objects (Instances) ● Classes ● Advantages of OOP ● Disadvantages of OOP ● Let’s Design an OOP Solution ● OOP Concepts ● UML - Unified Modelling Language ● UML Syntax ● Associations ● Inheritance ● Cohesion and Coupling
  • 3. Objects (Instances) An Object can be used to effectively represent real world entities ● Object has ○ States (descriptive characteristics) ■ Simple Attributes- Primitive data types ■ Complex Attributes - Contains collections ○ Behaviours ( what it can do) Example ● Keet’s Bank Account ○ State: Account number, Available balance ○ Behaviour: Make deposits, Withdraw
  • 4. Classes ● An object is defined by a class
  • 5. Advantages of OOP ● Code Reusing and Recycling ○ Saves development time and cost ● Encapsulation ○ Once object is created, knowledge of its implementation is not necessary for use. ● Design Benefits ○ Easy to understand. Large programs get more and more complex, but with OOP, designs can be made with less flaws ● Software Maintenance ○ Programs are not disposable. An OOP is much easier to modify and maintain than a non-OOP
  • 6. Disadvantages of OOP ● Size ○ OOPs are much larger than other programs ● Effort ○ OOPs require a lot of work and planning to develop ● Speed ○ OOPs are slower than other programs (Partially because of their size)
  • 7. Object Oriented Problem Solving Approach 1. Identify the Problem a. Carefully read the given problem and highlight the important points 2. Identify the Objects a. Identify the main objects. Sometime two entities can be selected as one, but sometimes, it might be better to have two instead of one complex one. 3. Identify the messages to be sent to other objects a. Identify what kind of interactions happen between objects in classes 4. Create a sequence of messages to the objects - to solve the problem a. Find a pattern to solve the final problem by interacting with different objects.
  • 8. Let’s Design an OOP Solution You need to create a Wedding Management System. Each wedding has a bride, a groom, flower decorator, food provider, location etc. Each bride and groom has their own parents and friends. Find a way to model this problem into an OOP solution. Just identifying the objects and the required interactions between them is sufficient. Represent the interactions by simple arrows.
  • 10. OOP Concepts ● Abstraction ○ Allows us to consider the important high level details ● Encapsulation ○ Allows us to consider what the program does and how it operates it. Without reading the technical details of how it actually works ● Inheritance ○ Generalization and Specialization. Specialized objects can automatically inherit all the characteristics of the more generalized objects. ● Polymorphism ○ Is the ability to interact with an object as its generalized category, regardless of its more specialized category.
  • 11. UML - Unified Modelling Language ● Class Diagrams ○ Classes show what the objects consists of and the methods ● Object Diagrams ○ Objects in the system and how they interact and the values in that object at a given state in time ● Sequence Diagrams ○ shows object interactions arranged in time sequence. How objects will interact to support one specific function ● Package Diagrams ○ Packages and dependencies between packages
  • 12. Class Consists of ● A unique Name ○ Conventionally starting with an Uppercase Letter ● A list of Attributes (Mostly Private) ○ Int, double, boolean, String, Complex Attributes ● A list of Methods (Mostly Public) ○ Unique method names starting with a Lowercase letter Visibility Modifiers (Access Modifiers) + for public access - for private access UML allows us to suppress any information we do not wish to highlight in our diagrams
  • 13. UML Syntax ● Attributes ○ <visibility> <name> : <type> <multiplicity> ■ Eg: + custRef : int [1] → a public attribute custRef is a single int value ● Methods ○ <visibility> <name> ( <parameter 1> : <type 1> , …….) : <Return Type> ■ Eg: + addName (newName : String) : Boolean
  • 14. Relationships Between Classes ● Some Class attributes can be complex ○ Can include some other class object as attributes ■ Eg: Teacher class has attribute → list of Students ○ String data type is a complex data type ■ Since it is part of the Java platform, it is implied that String is a primitive data type
  • 15. Example ● ‘n’ → exactly n ● ‘*’ → zero or more ● ‘m..n; → between m and n
  • 16. Types of Association ● Dependency A --------------------------> B ● Simple Association A B ● Bidirectional Association A B ● Aggregation A B ● Composition A B
  • 17. Dependency Class A in some way uses facilities defined by Class B. Changes to class B may affect class A. There are 3 ways in which dependencies can occur ● Class A has a method, which passes as a parameter object of Class B ● Class A uses a local variable of Class B ● Class A calls static methods in Class B
  • 18. Simple Association Class A uses objects of Class B. Typically Class A has an attribute of Class B. Navigability is from A to B. ● Class A objects can access Class B objects with which it is associated. ○ The reverse is not true. Eg: Teacher wants to maintain a list of Students. So navigability is from Teacher to Student. So Teacher object can access Student objects. But student objects do not necessarily need access to teacher objects.
  • 19. Bidirectional Association This is when Class A and Class B has a two way association. Each refers to the other class. Navigability is from A to B and B to A. Navigability from A to B means ● Class A object can access Class B objects ● Objects of Class A “Has a” Class A ● This implies reference from A to B Eg: Between a “Degree” and “Student”. Given a degree, we may need to know which students are studying on that degree. Alternatively, given a student, we may wish to know the degree they are studying.
  • 20. Aggregation Aggregation denotes a situation where object(s) of Class B “Belongs to” Class B. Aggregation also mentions that Objects of Class B, retain an existence independent of Class A. Eg: We can think of tyres belonging to a car. Tyres “Belong To” Cars. But if our context relates to a tyre shop or something, then Tyres can exist alone, in a garage as well.
  • 21. Composition ● Composition is similar to aggregation, but implies a much stronger relationship. ● Class B objects are an integral part of Class A. In general, objects of class B never exist other than as part of Class A. Both have the same lifetime. Eg: Between points, lines and shapes as elements of a picture. These objects can only exist as part of a picture, and if the picture is deleted, they are also deleted.
  • 22. Inheritance Class A Class B Class A inherits both implementation and interface of Class B. This is how specialization and generalization works. Specialized classes can inherit from generalized classes.
  • 23. Interfaces Class A Class B ● With interface inheritance, Class A will inherit only the interface of Class B. ● Class B contains only method headers ● Class A has to implement all methods defined in Class B
  • 24. Cohesion ● Cohesion describes how closely all routines in a class or all the code in a routing support a central purpose. ● Cohesion must be Strong. ● Classes must contain a strongly related functionality and aim for single purpose ● Cohesion is an important tool for managing complexities
  • 25. Coupling ● Coupling describes how tightly a class or routine is related to other classes or routines. ● Coupling must be kept Loose. ○ Modules must depend little on each other ○ One module can be replaced easily without causing trouble ○ A module can be easily used by other modules ● Two types of Coupling ○ Tight Coupling ○ Loose Coupling