Chapter 2 - Object Orientation Flashcards

To answer all the Object Oriented questions on the exam (63 cards)

1
Q

Encapsulation

A

helps hide implementation behind an interface or API.

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

Encapsulation code has 2 features

A
  1. ) Instance variables are kept protected - usually with the private modifier
  2. ) Getter and setter methods provide access to instance variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

IS-A

A

Refers to inheritance or implementation

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

IS-A

A

is expressed with the keyword extends

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

HAS-A

A

means an instance of one class “has a” reference to an instance of another class or another instance of the same class.

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

Polymorphism means

A

many forms

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

A reference variable

A

is always of a single, unchangeable type, but it can refer to a subtype object.

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

A single object can be referred to by reference variables of many different types

A

as long as they are the same type or supertype of the object.

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

The reference variables type (not the object type)

A

determines which methods can be called

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

Polymorphic method invocations

A

apply only to overridden instance methods

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

Methods can be overridden or overloaded

A

constructors can be overloaded but not overridden

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

Abstract methods

A

must be overridden by the first concrete (non-abstract) subclass

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

An overriding method

A
  1. must have same arg list
  2. must have same return type, the return type can be a subclass - known as a covariant return
  3. must not have a more restrictive access modifier
  4. my have a less restrictive access modifier
  5. Must not throw new or broader checked exceptions
  6. May throw fewer or narrower exceptions or any unchecked exception
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

final methods

A

cannot be overridden

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

Only inherited methods

A

may be overridden… private methods are NOT inherited

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

overloading means

A

reusing a method name, but with different arguments

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

Overloaded methods

A
  1. must have different argument lists
  2. May have different return types, if arg lists are also different
  3. May have different access modifiers
  4. May throw different exceptions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Methods from a superclass

A

can be overloaded in a subclass

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

Polymorphism applies to overriding

A

not to overloading

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

Object type (not the reference variables type)

A

determines which overriding method is used at runtime

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

Reference type determines

A

which overloaded method will be used at compile time

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

Two types of reference variable casting

A

downcasting and upcasting

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

Downcasting

A

Reference variables of subtypes must be explicitly cast, resulting in access to the subtypes members with this new reference variable.

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

Upcasting

A

can be done explicitly or implicitly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
When you are implementing an interface
you are fulfilling its contract
26
You implement an interface properly when...
you concretely override all of the methods defined by the interface
27
A single class can implement
many interfaces
28
Overloaded methods can change return types
overridden methods cannot, except in the case of covariant returns
29
An array is a legal return type
both to declare and return as a value
30
Methods with primitive return types
any value that can be implicitly converted to the return type can be returned
31
Nothing can be return from a void
but you can return nothing by simply saying return
32
Methods with an object reference return type
can return a subtype
33
Methods with an interface return type
can return any implementer
34
A constructor is always invoked
when a new object is created
35
Each superclass in an objects inheritance tree
will have a constructor called
36
Every class,even abstract class
has at least one constructor
37
Constructors must have the same name
as the class
38
Constructors don't have a return type
If you see a return type, its a method with the same name as the class, its NOT a constructor
39
Constructors can use
any access modifier (even private!)
40
The compiler will create a default constructor
if you don't create one in your class
41
The default constructor
is a no-arg constructor, if you don't create any constructors in your class
42
The first statement in a constructor MUST
call either this()... an overloaded constructor or super()
43
Instance members are accessible only
after the superclass constructor runs
44
Abstract classes have constructors
that are called when a concrete subclass is instantiated
45
Interfaces do not have
constructors
46
If your superclass does not have a no arg constructor
you MUST create a constructor and insert a call to super() with args matching those of the superclass
47
Constructors are never inherited
thus they cannot be overloaded
48
A constructor can be directly invoked only by another constructor
using a call to super() or this()
49
this
1. may appear only as the first statement in a constructor 2. the arg list determines which overloaded constructor is called
50
constructors can call constructors, can call constructors ...
sooner or later a call to super() or the stack will explode
51
calls to this() and super()
cannot be in the same constructor
52
use static methods
to implement behaviors that are not affected by the state of any instances
53
use static variables to hold data
that is class specific, there is only one copy of static variables
54
All static variables belong to the class
not to an instance
55
A static method cant access
instance variables directly
56
Use the dot operator
to access static members
57
static methods
can't be overridden, but they can be redefined
58
coupling
refers to the degree to which one class knows about or uses members of another class
59
lose coupling
is the desirable state of having classes that are well encapsulated
60
tight coupling
is the undesirable state
61
cohesion
refers to the degree in which a class has a single, well defined role or responsibility
62
Hi cohesion is desirable
members support a single, well-focused responsibility
63
low cohesion is undesirable
whose members support multiple, unfocused roles or responsibilities