Chapter 2 - Object Orientation Flashcards

To answer all the Object Oriented questions on the exam

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
Q

When you are implementing an interface

A

you are fulfilling its contract

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

You implement an interface properly when…

A

you concretely override all of the methods defined by the interface

27
Q

A single class can implement

A

many interfaces

28
Q

Overloaded methods can change return types

A

overridden methods cannot, except in the case of covariant returns

29
Q

An array is a legal return type

A

both to declare and return as a value

30
Q

Methods with primitive return types

A

any value that can be implicitly converted to the return type can be returned

31
Q

Nothing can be return from a void

A

but you can return nothing by simply saying return

32
Q

Methods with an object reference return type

A

can return a subtype

33
Q

Methods with an interface return type

A

can return any implementer

34
Q

A constructor is always invoked

A

when a new object is created

35
Q

Each superclass in an objects inheritance tree

A

will have a constructor called

36
Q

Every class,even abstract class

A

has at least one constructor

37
Q

Constructors must have the same name

A

as the class

38
Q

Constructors don’t have a return type

A

If you see a return type, its a method with the same name as the class, its NOT a constructor

39
Q

Constructors can use

A

any access modifier (even private!)

40
Q

The compiler will create a default constructor

A

if you don’t create one in your class

41
Q

The default constructor

A

is a no-arg constructor, if you don’t create any constructors in your class

42
Q

The first statement in a constructor MUST

A

call either this()… an overloaded constructor
or
super()

43
Q

Instance members are accessible only

A

after the superclass constructor runs

44
Q

Abstract classes have constructors

A

that are called when a concrete subclass is instantiated

45
Q

Interfaces do not have

A

constructors

46
Q

If your superclass does not have a no arg constructor

A

you MUST create a constructor and insert a call to super() with args matching those of the superclass

47
Q

Constructors are never inherited

A

thus they cannot be overloaded

48
Q

A constructor can be directly invoked only by another constructor

A

using a call to super() or this()

49
Q

this

A
  1. may appear only as the first statement in a
    constructor
  2. the arg list determines which overloaded constructor is called
50
Q

constructors can call constructors, can call constructors …

A

sooner or later a call to super() or the stack will explode

51
Q

calls to this() and super()

A

cannot be in the same constructor

52
Q

use static methods

A

to implement behaviors that are not affected by the state of any instances

53
Q

use static variables to hold data

A

that is class specific, there is only one copy of static variables

54
Q

All static variables belong to the class

A

not to an instance

55
Q

A static method cant access

A

instance variables directly

56
Q

Use the dot operator

A

to access static members

57
Q

static methods

A

can’t be overridden, but they can be redefined

58
Q

coupling

A

refers to the degree to which one class knows about or uses members of another class

59
Q

lose coupling

A

is the desirable state of having classes that are well encapsulated

60
Q

tight coupling

A

is the undesirable state

61
Q

cohesion

A

refers to the degree in which a class has a single, well defined role or responsibility

62
Q

Hi cohesion is desirable

A

members support a single, well-focused responsibility

63
Q

low cohesion is undesirable

A

whose members support multiple, unfocused roles or responsibilities