OPO Flashcards

1
Q

What is an example of dynamic binding?

A

Method overriding

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

For which case would the use of a static attribute be appropriate?

A

The weather conditions for each house in a small neighborhood

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

Why would you create an abstract class, if it can have no real instances?

A

to avoid redundant coding in children. and to have common behavior in derived classes

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

When does static binding happen?

A

at compile time

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

What is the best reason to use a design pattern?

A

It will result in code that is more extensible and maintainable

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

What is encapsulation?

A

hiding the data and implementation details within a class

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

What is an is-a relationship?

A

A subclass object has an is-a relationship with its superclass or interface

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

You want a method with behavior similar to a virtual method. It’s meant to be overridden, except that it does not have a method body. It just has a method signature. What kind of method should you use?

A

an abstract method

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

Which code creates a new object from the Employee class?

A

Employee current Employee = new Employee();

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

Which type of constructor cannot have a return type?

A

Trick question, constructors do not have a return type

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

When is a constructor executed?

A

When an object is created from a class using the new keyword

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

If a local class is defined in a function, what is true for an object of that class?

A

The object can be accessed, declared, and used locally in that function.

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

Which two blocks are used to handle and check errors

A

try and catch

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

Why would you implement composition using an id instead of a reference?

A

It makes it easier to save the entity

It can make the entity retrieval more efficient

It minimizes coupling

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

Which statement best describes the method of inheritance in OOP?

A

Inheritance describes the ability to create new classes based on an existing class

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

Which type of inheritance, when done continuously, is similar to a tree structure?

A

Hierarchical

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

Is a default parameter’s constructor equivalent to the default constructor?

A

No

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

What are some advantages of using getters and setters?

A

Getters and setters provide encapsulation of behavior

Getters and setters provide a debugging point for when a property changes at runtime

Getters and setters permit different access levels.

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

In context of OOP, what is association?

A

Association is a relationship where all objects have their own life cycle and there is no owner

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

How are user stories different from use cases?

A

User Stories are shorter and less detailed

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

Which type of inheritance must be used so that the resultant is hybrid?

A

Multiple and hierarchical

Hybrid inheritance is a composition of multiple and hierarchical inheritances

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

A language that does not support polymorphism but supports classes is considered what?

A

an object-based language

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

If two classes combine some private data members and provides public member functions to access and manipulate those data members. Where is abstraction used?

A

Abstraction is using public member functions to access and manipulate the data members

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

What are the five Creational Design patterns by the Gang of Four?

A
Abstract Factory
Builder
Factory Method
Prototype
Singleton
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

In multilevel inheritance, one class inherits how many classes?

A

one class only

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

if an object is passed by reference, the changes made in the function are reflected ____.

A

to the main object of the caller function, too

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

A mobile phone is made up of components such as a motherboard, camera, and sensors. The motherboard represents all the functions of a phone, the display shows the display only, and the phone is represented as a whole. Which of the following has the highest level of abstraction?

A

The mobile phone

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

Which class has the highest degree of abstraction in a multilevel inheritance relationship of five levels?

A

the class at the first level

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

Which is NOT one of the basic types of inheritance?

A

double inheritance

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

Why is code duplication so insidious?

A

One has to maintain all the duplicates

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

When and how often is a static constructor called?

A

It is called initially when an object is created and only one time

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

What does the code shown below demonstrate, and why?

static void Multiply(int num1, int num2) {};
static void Multiply(double num1, double num2, double num3) {};
static void Multiply(float num1, float num2) {};

A

Method overloading

It allows the creation of several methods with the same name, which differ by the type of input via parameter

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

What is the purpose of a static constructor?

A

To initialize all the members with static value

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

What are CRC Cards?

A

Class responsible collaboration cards are a brainstorming tool used in the design of oop software

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

How are contents of a composition different from those of aggregation?

A

if a composition dies, the contents die

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

Which statement about compositions and aggregations is true?

A

if a composition dies, the contents die

37
Q

What is the result of using more abstraction?

A

it can limit code readability

38
Q

What is an abstract class?

A

A class with no body, that is meant to be inherited (implemented?)

39
Q

Do member functions need to be declared inside the class definition?

A

Yes

40
Q

Why is inheritance used when creating a new class?

A

To avoid writing duplicate code

41
Q

In addition to attributes and behaviors, what quality must a class possess?

A

a name

42
Q

Which words in the following list are candidates for objects: trumpet, clean, enrage, leaf, tree, collapse, active, and lively?

A

leaf, tree, and trumpet

43
Q

What best describes what object-oriented programming does?

A

It focuses on objects that interact cleanly with one another

44
Q

Can abstract classes be used in multilevel inheritance?

A

Yes

45
Q

What type of inheritance may lead to the diamond problem?

A

Multiple inheritance

46
Q

What is the relationship between abstraction and encapsulation?

A

Abstraction is about making relevant information visible, while encapsulation enables a programmer to implement the desired level of abstraction

47
Q

public and private are examples of?

A

Access Specifiers

48
Q

What is a reference to an object?

A

It is the address where the variables and methods of an object are stored

49
Q

Why is unit testing harder in OOP than functional programming?

A

Objects may maintain an internal state, which is not easily accessible by the tests

50
Q

What is the function of a user diagram?

A

It links actors to roles played in all use cases

51
Q

How do object behavior and attributes differ?

A

Attributes describe a state; behaviors describe a change

52
Q

The open/closed principle states that classes should be open for __ but closed for __.

A

Open for extension but closed for modification

53
Q

Why would you override a method of a base class?

A

to define a custom implementation of an inherited member

54
Q

What is a copy constructor?

A

A unique constructor for creating a new object as a copy of an object that already exists. There will always be only one copy constructor that can be either defined by the user or the system

55
Q

What defines the catch block most accurately?

A

The catch block that will be executed is the one that best matches the type of the exception thrown

56
Q

There are five classes. Class E is derived from class D, D from C, C from B, and B from A. Which class constructor(s) will be called first if the object of E or D is created?

A

A

57
Q

You have modules that are dependent on each other. If you change one module, you have to make changes in the dependent modules. What term is used to describe this problem, and what is a potential solution?

A

???

Cohesion. A solution is to show that each module has certain responsibilities and to use an anticohesive design pattern.

Encapsulation. A solution is to implement one of the SOLID principles to ensure the modules do not encapsulate with each other.

Coupling. A solution is to refactor the code to be loosely coupled by using inversion of control and dependency injection
.
Dependency. A solution is to implement polymorphism and abstraction to change and extract dependent elements of a module so that it functions on its own.

58
Q

__________ describes an aggregation

A

???

A class of resources
A group of methods
A collection of objects
A list of children

59
Q

And whereas a class can extend only one abstract class, it can take advantage of multiple interfaces.

A

x

60
Q

An abstract class can have constructors—this is one major difference between an abstract class and an interface

A

x

61
Q

An interface is basically a contract—it doesn’t have any implementation. An interface can contain only method declarations; it cannot contain method definitions.

A

x

62
Q

Abstract classes provide you the flexibility to have certain concrete methods and some other methods that the derived classes should implement. By contrast, if you use interfaces, you would need to implement all the methods in the class that extends the interface. An abstract class is a good choice if you have plans for future expansion – i.e. if a future expansion is likely in the class hierarchy. If you would like to provide support for future expansion when using interfaces, you’ll need to extend the interface and create a new one.

A

x

63
Q

n interface differs from an abstract class because an interface is not a class. An interface is essentially a type that can be satisfied by any class that implements the interface.

A

x

64
Q

But the real question is why did we declare the getArea method to be abstract in the Figure class? Well, what does the getArea method do? It returns the area of a specific shape. But, because the Figure class isn’t a specific shape (like a Circle or a Rectangle), there’s really no definition we can give the getArea method inside the Figure class. That’s why we declare the method and the Figure class to be abstract. Any classes that derive from the Figure class basically have 2 options:

  1. The derived class must provide a definition for the getArea method OR
  2. The derived class must be declared abstract itself.
A

x

65
Q

An abstract class is good if you think you will plan on using inheritance since it provides a common base class implementation to derived classes.

A

a

66
Q

An abstract class is also good if you want to be able to declare non-public members. In an interface, all methods must be public.

A

a

67
Q

If you think you will need to add methods in the future, then an abstract class is a better choice. Because if you add new method headings to an interface, then all of the classes that already implement that interface will have to be changed to implement the new methods. That can be quite a hassle.

A

c

68
Q

Interfaces are a good choice when you think that the API will not change for a while.

A

c

69
Q

Interfaces are also good when you want to have something similar to multiple inheritance, since you can implement multiple interfaces.

A

f

70
Q

An abstract class can never be sealed or static.

An abstract class can have abstract as well as non abstract methods.

The abstract keyword can be used with class, methods, properties, indexers and events.

Abstract members can only be declared inside an abstract class.

An abstract member cannot be static or private.

An abstract method cannot be marked virtual.

A concrete class cannot inherit more than one abstract class, in other words multiple Inheritance is not possible.

Without an abstract class, we cannot implement the Template Method Pattern.

A

fdh

71
Q

However, there is the advantage of using an interface over an abstract class; that is “Multiple Inheritance Support”.

A

However, there is the advantage of using an interface over an abstract class; that is “Multiple Inheritance Support”.

72
Q

derived class

A

derived class

73
Q

By the definition of abstract class, any class that implements it must provide definitions to all its abstract members.

A

vs interface

74
Q

What is the only way to do multiple inheritance in C#?

A

By using interfaces

75
Q

no access modifier is allowed with interface methods

A

also cannot declare with Static

76
Q

implemented vs inherited?

A

abstract is inherited, interfaces are implemented

77
Q

In derived classes, the access modifier must always be _____?

A

derived classes, the access modifier must always be public

78
Q

Can an interface be instantiated?

A

An interface has no implementation and cannot be instantiated. However, it can be referenced to the class object that implements it.

79
Q

Tell the compiler which method is specific to which interface using Explicit Implementation. It can be done by prefixing the interface name with the method definitions in the derived class.

A
interface IDebitCard    
     {     
       void CardNumber();    
     }    
     //Second Interface ICreditCard    
     interface ICreditCard    
     {    
       void CardNumber();    
     }    
     //Customer Class implements both the interfaces    
     class Customer: IDebitCard, ICreditCard    
     {   
   void IDebitCard.CardNumber()
80
Q

Why might you choose an abstract class over an interface and vice versa?

A

If you have some kind of default functionality to share across classes in the hierarchy, you can use an abstract class. But if you don’t have any default implementation and just need to define contracts for derived classes to follow; interface is the most preferred way.

81
Q

It is a standard rule when using an interface, be sure you have done it right the first time. Why?

A

Once the interface is implemented by derived classes, it is difficult to update or modify the interface since everyone else’s code breaks.

82
Q

Now if the Apple class wants to implement TouchID features, it can easily be done by defining another interface IFeatures.

A
interface ISmartPhone     
     {    
         void OS();    
         void AppStore();    
     }    
     //New Interface meant only for Apple Class    
     interface IFeatures    
     {    
          void TouchID();   
     }   
     class Apple: ISmartPhone, IFeatures    
     {
83
Q

What is an abstract class?

A

An abstract class is a half defined parent class

84
Q

What is an interface?

A

An interface is a contract

85
Q

What are events?

A

Events are encapsulation over delegates

86
Q

What kind of model do events create?

A

Events create a publisher subscriber model

87
Q

What is a delegate?

A

A Delegate is a pointer to a function

88
Q

What is a delegate useful for?

A

Delegates are very useful as callbacks to communicate between threads