Lecture 7 - OOP Foundations Flashcards

1
Q

What is a publicized service made available to others?

A

Interface

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

TF: The implementation of an interface is usually visible to user of the interface

A

False. Implementation generally hidden

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

At what time is a collection of classes organized into packages (hint: static point of view)?

A

At compile-time

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

At what time is a program a collaborating community of objects that uses class features (data, method)?

A

At runtime

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

What are Basic (primitive) types?

A
  • int
  • long
  • double
  • void
  • boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are Reference types?

A
  • Class
  • Interface
  • Array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

TF: A stack cannot hold the value of a primitive type

A

False. It can

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

TF: A stack can hold the value NULL

A

True

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

TF: A stack cannot hold a reference (pointer) to an object allocated in Heap

A

False. It can

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

TF: A stack can hold Objects

A

False. It cannot

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

TF: A heap can only hold objects that were created via “new”

A

True

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

What are the two things defined by a class?

A
  • A type
  • An implementation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is defined by an interface?

A
  • A type
    (without an implementation)
    Note: interface has no logic (logic defined by class implementing interface)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the two types an expression can have?

A
  • Compile-time (static) type
  • Runtime (dynamic) type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The compile-time type is also known as…

A

The declared type

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

Animal a = new Cat();
What is the declared type of the provided code?

A

Animal

17
Q

Animal a = new Cat();
What is the run-time type of the provided code?

A

Cat

18
Q

Will the following code run?
Animal a = new Animal();
Cat c = (Cat) a;

A

No. Cannot cast downwards

19
Q

Will the following result in a compile-time error or runtime error?
Animal a = new Animal();
Cat c = (Cat) a;

A

Runtime error. The compiler thinks Animal “a” could be a Cat

20
Q

Will the following code run?
Cat c = new Cat();
Animal a = (Animal) c;

A

Yes. Casting upwards is allowed

21
Q

What is the purpose of Casting? (2)

A
  • Inform compiler of (assumed) subtype of an object
    [ex: Animal a = new Cat()]
  • So compiler can perform better type checking
22
Q

TF: Dynamic dispatching is when the runtime decides which implementation of a non-static method to call based on the calling object

A

True

23
Q

Which sleep method gets called for the following:
Animal a = new Cat();
a.sleep();

A

Since Cat is the actual type, the Cat’s sleep method gets called

24
Q

TF: Dynamic dispatching can occur on static methods

A

False. Only on non-static methods

25
Q

TF: Dynamic dispatching happens for constructors

A

False. Object constructor is decided at compile-time

26
Q

Given the following code,the compiler will check where for the existence of the method?
A a = new Cat();
a.m();

A

It will check the declared type (i.e. A) and all superclass of it for the method existence.