OOP Flashcards

1
Q

What is OOP?

A

OOP is a programming methodology that considers a program as consisting of objects that interact with each other by means of actions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an object?

A

An object is an identifiable entity that has a set of attributes, behaviour and state

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name the basic units of an object-oriented system

A

Objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Define attributes

A

Attributes are individual characteristics that differentiate one object from another

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Define behaviour

A

Behaviour is defined by the set of actions an object can perform

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Define state

A

State is defined by the set of values held by its attributes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are member variables or instance variables?

A

While implementing a real-world object in software form, all its attributes are represented through data items known as member variables or instance variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are member methods?

A

While implementing a real-world object in software form, all its behaviors are represented through data items known as member methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

In a software object, sum up the attribute+behavior+state

A

Member variables that hold the attributes
The values of these variables define the state of obj
Member methods that define the behavior of obj

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a class?

A

A class is a template or blueprint for multiple objects with similar features and may be regarded as a specification for creating similar objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which objects are grouped together in a class?

A

Objects that share the same attributes and behavior are grouped together in a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why is a class called an object factory?

A

A class is a blueprint for multiple objects with similar features and may be regarded as a specification for creating similar objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What do you need to do to create objects belonging to a class?

A

Once a class has been defined, you can create many objects belonging to that class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is known as an instance of a class?

A

An object belonging to a particular class is known as an instance of a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

State the differences between a class and an object

A
  1. The way attributes and methods are treated in the class and the object
  2. The class is just a specification of the object. The attributes and methods in the class are thus declarations that do not contain any values. However, an object is a concrete instance of a class with properly defined values of each attribute and behaves as per the methods of a class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In one line, summarize the specification difference between object and class

A

The class is a logical construct whereas the object has a physical reality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Name the four fundamental principles of OOP

A
  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Define abstraction

A

Abstraction refers to the act of representing essential features without including the background details

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Define encapsulation

A

Encapsulation is a mechanism that binds the data and code (methods) together into a single unit.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How does encapsulation promote protection of data?

A

Encapsulation keeps the data and methods safe from the outside world, preventing any unauthorized access or misuse. Access to the data and code inside a class is strictly controlled. Only the methods inside the class can access the data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

In a camera, where do abstraction and encapsulation come into play?

A

The Capture button shows the essential feature and not the details - abstraction
The encapsulation helping to hide all the internal details of taking a photograph - opening the aperture, streaming light through lens, etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do objects encapsulate state and behavior?

A
  1. An object stores its state in member variables and exposes its behavior through member methods.
  2. The member methods operate on member variables and serve as the primary mechanism to interact with the object.
  3. Only the member methods which are defined inside the class can access the data and change its state.
  4. Hence, the state and behavior are said to be encapsulated by the object, hiding the internal state and requiring all interactions to be performed through the methods of the object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How can the data of an object be accessed and its state changed?

A

Only the member methods which are defined inside the class can access its data and change its state

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Define inheritance

A

Inheritance is a powerful mechanism by which one class acquires the property of another class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What is child class?

A

The class that is derived from another class

26
Q

Give other names for child class

A

Derived class or sub class

27
Q

What is parent class?

A

The class from which another class is derived is called the parent class

28
Q

Give other names for parent class

A

Base class or super class

29
Q

What does the word Polymorphism mean?

A

It means many forms. It is the ability of a method or object to take on multiple forms

30
Q

Where does the word Polymorphism come from?

A

From the Greek word poly (many) and morphos (form)

31
Q

Define polymorphism in terms of OOP

A

Polymorphism is a mechanism by which you can send the same message to different objects, and each object can respond in a different way depending on its class

32
Q

In the statement ‘Student sumit;’ how does class as a user-defined data type come in?

A

The Student class may be considered as a data type after being defined, and an object as a variable of that data type. The statement will create a student object sumit belonging to the Student class

33
Q

When does a class behave like built-in data types?

A
WashingMachine samsung;
Once the WashingMachine class has been defined, the statement will create a samsung object belonging to the WashingMachine class. 
Hence, class is a user-defined data type, which has its own functionality and behaves like built-in data types
34
Q

Define message passing

A

Objects interact with each other by passing messages to each other. This interaction is known as message passing.

35
Q

What is a message?

A

A message is a request to an object to perform an action (behavior)

36
Q
  1. MusicPlayer Alexa
  2. Alexa.PlaySong()
    Define the significant parts of both statements
A
  1. The Alexa object belonging to the class MusicPlayer

2. Request to the Alexa object to invoke its member method PlaySong() using the dot(.) operator

37
Q

What is the use of dot operator in message passing?

A

The dot operator is used between an object and its member method to invoke the member method

38
Q

What is the message sending and receiving object called?

A

Message sending object - sender

Message receiving object - receiver

39
Q

Name two objects between which message passing will take place.

A

Person objJoseph;

WashingMachine objSamsung;

40
Q

What might the message look like between instance objJospeh and instance objSamsung?

A

objSamsung.StartWash()

41
Q

Give the syntax of a message

A

ObjectName.MemberMethod()

42
Q

Which terms in OOP are often interchangeable?

A

Object and instance

43
Q

How many abstractions of an entity can there be?

A

Multiple abstractions, depending on the perspective of the viewer

44
Q

How can you make the entire data and code contained in an object a user-defined data type?

A

Using the concept of a class. The class may now be considered as a data type and an object as a variable of that data type.

45
Q

Which approach does OOP mainly use?

A

Bottom-up programming approach

46
Q

Which approach does POP mainly use?

A

Top-down programming approach

47
Q

POP places emphasis on?

A

instructions/functions

48
Q

What is the POP paradigm?

A

It is a programming paradigm where a complex programming problem is solved by dividing it into smaller problems using procedures. Any procedure can be called by the main program as well as the other procedures

49
Q

Explain the OOP paradigm

A

OOP is a programming paradigm that revolves around the behavior of an object, and its interactions with other objects and classes. OOP follows the design principle of data abstraction, Encapsulation, Inheritance, and Polymorphism

50
Q

What does inheritance allow a class to do?

A

To use the attributes and behaviors of its parent class

51
Q

In polymorphism, what does the behaviour of an operation depend on?

A

An operation is allowed to exhibit different behavior in different instances. The behavior depends upon the type of data used in the operation

52
Q

Give a software example of OOP

A

For two integers, the operation of addition will generate a sum. For two strings, it will produce a third string by concatenation

53
Q

Write two major differences between POP and OOP

A
  1. In POP, the real world is represented by procedures operating on data but in OOP, the real world is represented by objects and the operations which can be performed on these objects
  2. Data and functions are separate in POP, but in OOP, the data and functions are encapsulated into a single entity
54
Q

Why is an object called an instance of a class?

A

Every object created from the class gets its own instance of member variables and methods defined in the class. Multiple objects can be created from the class

55
Q

Why is a class known as a composite data type?

A

A class is composed of member variables that are of different data types. Hence, a class can be viewed as a composite data type.

56
Q

What does a class encapsulate?

A

A class encapsulates the member variables and member methods

57
Q

Give the characteristics of OOP

A
  1. Emphasis on data items rather than functions
  2. Makes program simpler by dividing into a no. of
    objects
  3. Objects can be used as a bridge to have data flow
    from one function to another
  4. The concept of data hiding enhances security in
    problems
58
Q

What are the limitations of OOP?

A
  1. Object-oriented programs typically involve more lines
    of code than procedural programs
  2. Object-oriented programs are typically slower than
    procedure
  3. In certain scenarios, these programs can consume
    a large amount of memory.
59
Q

Give the characteristics of POP

A
  1. Emphasis is on functions/methods
  2. Functions share global data
  3. Data values can keep floating from one function to
    another
  4. It uses the top-down approach of programming
60
Q

What are the limitations of POP?

A
  1. As data values are global to all functions, you may
    require to make necessary changes in all the
    functions due to any change in the data values
  2. It is not suitable to solve complex problems in real-
    life situations
61
Q

Code and data held together in POP or OOP?

A

Code and data are held together in OOP, and held separately in POP