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
What is a parameterized constructor used for?
To provide different values to distinct objects
26
In Java, a constructor is just like a method but without what?
A return type
27
What is the technique in Java of having multiple constructors with different parameter lists?
Constructor overloading
28
How are constructors arranged in constructor overloading?
Such that they perform different tasks
29
How does the compiler differentiate constructors in constructor overloading?
By the number & types of parameters
30
Is a constructor or a method used to intialize the state of an object?
Constructor
31
Is a constructor or a method used to expose the behavior of an object?
Method
32
Must or must not a constructor have a return type?
Must not
33
Must or must not a method have a return type?
Must
34
Is a constructor invoked explicitly or implicitly?
Implicity
35
Is a method invoked explicitly or implicitly?
Explicitly
36
Does the Java compiler provide a constructor if one is not already present?
Yes
37
Does the compiler provide a method?
No
38
Must the constructor name be the same as the class name?
Yes
39
Must the method name be the same as the class name?
No
40
What is a mechanism in Java in which one object acquires all the properties & behaviors of a parent object?
Inheritance
41
What is the basic premise behind inheritance?
To create new classes that are built upon existing ones.
42
When inheriting from an existing class, what two things can be reused from the parent?
Methods and fields
43
Can you add new methods and fields to the child class during inheritance?
Yes
44
What is another name for the parent-child relationship that inheritance represents?
IS-A relationship
45
What are two advantages of inheritance?
Method overloading (for runtime polymorphism), and code reusability
46
What are three other names for the child class?
Sub class, derived class, extended class
47
What are two other names for the parent class?
Super class, base class
48
What keyword in the code indicates the creation of a new class that derives from an existing class?
Extends
49
What are the three basic types of inheritance in Java?
Single, multilevel, hierarchical
50
What are the two types of inheritance only supported through the interface?
Multiple, hybrid
51
Why is multiple inheritance not supported in Java?
To reduce complexity and simplify the language
52
Does multiple inheritance cause Java render a runtime error or a compile-time error?
Compile-time error
53
What term refers to the ability of an object to take on many forms?
Polymorphism
54
What is the most common use of polymorphism in OOP?
When a parent class reference is used to refer to a child class object
55
What term describes if a class has multiple methods with the same name but different parameters?
Method overloading
56
What are the two ways to overload a method in Java?
Changing the number of arguments, changing the data type of the arguments
57
Can you overload the main method in Java?
Yes
58
What term in Java describes if a child class has the same method as declared in the parent class?
Method overriding
59
One usage of method overriding is to provide specific implementation of ____ which is already provided by its parent class.
A method
60
One usage of method overriding is ____
Runtime polymorphism
61
In method overriding, the method must have the same ____ and ____as its parent class.
Name, parameter
62
What relationship must be present in method overriding?
IS-A relationship (inheritance)
63
Why can't a static method be overridden?
It is bound with a class (whereas an instance method is bound with an object)
64
Is method overloading or overriding used to increase the readability of the program?
Overloading
65
Is method overloading or overriding performed within a class?
Overloading
66
Does method overloading or overriding occur in two classes with an inheritance relationship?
Overriding
67
In method overloading, must the parameter be different or the same?
Different
68
In method overriding, must the parameter be different or the same?
The same
69
Is method overloading an example of compile time or run time polymorphism?
Compile time polymorphism
70
Is method overriding an example of compile time or runtime polymorphism?
Runtime polymorphism
71
Between method overloading and overriding, in which does it not matter if the return type is the same or different?
Overloading
72
Between method overloading and overriding, in which must the return type be the same or covariant?
Overriding
73
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?
Encapsulation
74
How can a fully encapsulated class in Java be created?
By making all the data members of the class private
75
What is the "Java Bean" class an example of?
A fully encapsulated class
76
What can be done to make an encapsulated class read-only or write-only?
Provide only a getter or setter method
77
What are the two types of modifiers in Java?
Access and non-access
78
The access modifier in Java specifies the accessibility (scope) of any of what four things?
Data member, method, constructor, class
79
What are the four types of Java access modifiers?
Private, default, protected, public
80
Which access modifiers can be applied within a class?
Public, private, default, protected
81
Which access modifiers can be applied within a package?
Default, protected, public
82
Which access modifiers can be applied outside a package by a subclass?
Protected, public
83
Which access modifier can always be applied outside a package?
Public
84
What is the process of hiding the implementation details and showing only functionality to the user?
Abstraction
85
What is the process of extracting shared characteristics from two or more classes, and combining them into a generalized superclass?
Generalization
86
What are the three applicable shared characteristics in generalization?
Attributes, associations, methods
87
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?
Specialization
88
What are the two ways to achieve abstraction?
Abstract class (0 to 100%), Interface (100%)
89
Can an abstract class have non-abstract methods?
Yes
90
An abstract class needs to be ____ and its method needs to be ____
Extended, implemented
91
Can an abstract class be instantiated?
No
92
How must an abstract class be declared?
With the abstract keyword
93
Can an abstract class have constructors? Can it have static methods?
Yes, yes
94
Abstract classes can have final methods which will do what?
Prevent the subclass from changing the body of the method