OOP - Object Oriented Programming Flashcards

1
Q

What are six core concepts of Object Oriented Programming

A

Objects, Classes, Inheritance, Polymorphism, Abstraction, Encapsulation

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

An entity that has a state & behavior, and can be physical or logical

A

Object

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

An object can be defined as an instance of a _____

A

Class

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

What can objects do without knowing the details of each other’s data or code?

A

Communicate

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

What is necessary for objects to communicate?

A

The type of message accepted and the type of response returned

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

Java classes define what two things relating to objects?

A

Data types and methods

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

A class can be defined as a ____ from which you can create an individual object.

A

Blueprint

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

Do classes consume space?

A

No

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

What are two advantages of Object Oriented Programming compared to Procedure Oriented Programming?

A

Easier development & maintenance (including when upscaling), Data hiding

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

A Java constructor is a block of code similar to what?

A

The method

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

What Java entity is called when an instance of an object is created and memory is allocated for the object?

A

A constructor

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

A Java constructor is a special type of method which is used to do what?

A

Initialize the object

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

When an object is created, the compiler makes sure that constructors for all of its ____ are called.

A

Subobjects (member & inherited objects)

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

What must members have for constructors to be called automatically when an object is created?

A

Default constructors / constructors without parameters

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

What can be done when an object is created but members do not have default constructors or constructors without parameters?

A

Parameterized constructors can be called using an initializer list

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

Why do constructors have this name?

A

Because they construct values at the time of object creation

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

Does the Java compiler create a default constructor if your class doesn’t have any?

A

Yes

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

One of three rules defined for the constructor is that the constructor name must be the same as ____.

A

Its class name

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

One of three rules defined for the constructor is that a constructor must have no explicit ____.

A

Return type

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

One of three rules defined for the constructor is that a Java constructor cannot be what three things?

A

Abstract, static/final, asynchronized

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

What are the two types of constructors?

A

Default and parameterized

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

The default constructor is a ____ constructor that the Java compiler inserts on your behalf.

A

No-argument

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

What is the (default) behavior of the default constructor?

A

It contains a “default” call to super();

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

If you implement any constructor, will you continue to receive a default constructor?

A

No

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

What is a parameterized constructor used for?

A

To provide different values to distinct objects

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

In Java, a constructor is just like a method but without what?

A

A return type

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

What is the technique in Java of having multiple constructors with different parameter lists?

A

Constructor overloading

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

How are constructors arranged in constructor overloading?

A

Such that they perform different tasks

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

How does the compiler differentiate constructors in constructor overloading?

A

By the number & types of parameters

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

Is a constructor or a method used to intialize the state of an object?

A

Constructor

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

Is a constructor or a method used to expose the behavior of an object?

A

Method

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

Must or must not a constructor have a return type?

A

Must not

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

Must or must not a method have a return type?

A

Must

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

Is a constructor invoked explicitly or implicitly?

A

Implicity

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

Is a method invoked explicitly or implicitly?

A

Explicitly

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

Does the Java compiler provide a constructor if one is not already present?

A

Yes

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

Does the compiler provide a method?

A

No

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

Must the constructor name be the same as the class name?

A

Yes

39
Q

Must the method name be the same as the class name?

A

No

40
Q

What is a mechanism in Java in which one object acquires all the properties & behaviors of a parent object?

A

Inheritance

41
Q

What is the basic premise behind inheritance?

A

To create new classes that are built upon existing ones.

42
Q

When inheriting from an existing class, what two things can be reused from the parent?

A

Methods and fields

43
Q

Can you add new methods and fields to the child class during inheritance?

A

Yes

44
Q

What is another name for the parent-child relationship that inheritance represents?

A

IS-A relationship

45
Q

What are two advantages of inheritance?

A

Method overloading (for runtime polymorphism), and code reusability

46
Q

What are three other names for the child class?

A

Sub class, derived class, extended class

47
Q

What are two other names for the parent class?

A

Super class, base class

48
Q

What keyword in the code indicates the creation of a new class that derives from an existing class?

A

Extends

49
Q

What are the three basic types of inheritance in Java?

A

Single, multilevel, hierarchical

50
Q

What are the two types of inheritance only supported through the interface?

A

Multiple, hybrid

51
Q

Why is multiple inheritance not supported in Java?

A

To reduce complexity and simplify the language

52
Q

Does multiple inheritance cause Java render a runtime error or a compile-time error?

A

Compile-time error

53
Q

What term refers to the ability of an object to take on many forms?

A

Polymorphism

54
Q

What is the most common use of polymorphism in OOP?

A

When a parent class reference is used to refer to a child class object

55
Q

What term describes if a class has multiple methods with the same name but different parameters?

A

Method overloading

56
Q

What are the two ways to overload a method in Java?

A

Changing the number of arguments, changing the data type of the arguments

57
Q

Can you overload the main method in Java?

A

Yes

58
Q

What term in Java describes if a child class has the same method as declared in the parent class?

A

Method overriding

59
Q

One usage of method overriding is to provide specific implementation of ____ which is already provided by its parent class.

A

A method

60
Q

One usage of method overriding is ____

A

Runtime polymorphism

61
Q

In method overriding, the method must have the same ____ and ____as its parent class.

A

Name, parameter

62
Q

What relationship must be present in method overriding?

A

IS-A relationship (inheritance)

63
Q

Why can’t a static method be overridden?

A

It is bound with a class (whereas an instance method is bound with an object)

64
Q

Is method overloading or overriding used to increase the readability of the program?

A

Overloading

65
Q

Is method overloading or overriding performed within a class?

A

Overloading

66
Q

Does method overloading or overriding occur in two classes with an inheritance relationship?

A

Overriding

67
Q

In method overloading, must the parameter be different or the same?

A

Different

68
Q

In method overriding, must the parameter be different or the same?

A

The same

69
Q

Is method overloading an example of compile time or run time polymorphism?

A

Compile time polymorphism

70
Q

Is method overriding an example of compile time or runtime polymorphism?

A

Runtime polymorphism

71
Q

Between method overloading and overriding, in which does it not matter if the return type is the same or different?

A

Overloading

72
Q

Between method overloading and overriding, in which must the return type be the same or covariant?

A

Overriding

73
Q

What is the process in Java of wrapping code and data together into a single unit, for example, a bottle which contains several mixed medicines?

A

Encapsulation

74
Q

How can a fully encapsulated class in Java be created?

A

By making all the data members of the class private

75
Q

What is the “Java Bean” class an example of?

A

A fully encapsulated class

76
Q

What can be done to make an encapsulated class read-only or write-only?

A

Provide only a getter or setter method

77
Q

What are the two types of modifiers in Java?

A

Access and non-access

78
Q

The access modifier in Java specifies the accessibility (scope) of any of what four things?

A

Data member, method, constructor, class

79
Q

What are the four types of Java access modifiers?

A

Private, default, protected, public

80
Q

Which access modifiers can be applied within a class?

A

Public, private, default, protected

81
Q

Which access modifiers can be applied within a package?

A

Default, protected, public

82
Q

Which access modifiers can be applied outside a package by a subclass?

A

Protected, public

83
Q

Which access modifier can always be applied outside a package?

A

Public

84
Q

What is the process of hiding the implementation details and showing only functionality to the user?

A

Abstraction

85
Q

What is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass?

A

Generalization

86
Q

What are the three applicable shared characteristics in generalization?

A

Attributes, associations, methods

87
Q

If certain attributes, associations, or methods only apply to some of the objects in a class, what is the process of creating new subclasses from an existing class?

A

Specialization

88
Q

What are the two ways to achieve abstraction?

A

Abstract class (0 to 100%), Interface (100%)

89
Q

Can an abstract class have non-abstract methods?

A

Yes

90
Q

An abstract class needs to be ____ and its method needs to be ____

A

Extended, implemented

91
Q

Can an abstract class be instantiated?

A

No

92
Q

How must an abstract class be declared?

A

With the abstract keyword

93
Q

Can an abstract class have constructors? Can it have static methods?

A

Yes, yes

94
Q

Abstract classes can have final methods which will do what?

A

Prevent the subclass from changing the body of the method