Interface, Types, and Typecasting + Polymorphism Flashcards

1
Q

When a class implements an interface, it promises to provide _______ the behavior published by that interface.

A

ALL

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

TRUE OR FALSE:

Interfaces cannot be instantiated

A

TRUE

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

Every field declaration in the body of an interface is implicitly ___________________________.

A

public static final

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

Methods in an interface are ____________

A

Abstract methods

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

multiple interfaces gives the illusion of _____________

A

multiple inheritance

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

The type of one object is converted to match the type of another object
reference

A

Type Casting

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

T or F

Casts can be applied to both primitive data types and object references

A

T

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

Types of Casting

A

Explicit Casting
char c = (char) i

Implicit Casting
float num = i

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

Widening vs Narrowing Conversion

A

Narrowing conversion may cause less of precision and range (float to int / superclass to subclass)

Widening conversion may cause increase in precision and range
(int to float / subclass to superclass)

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

In type casting objects, the cast must be to ________________________

A

subclass types, superclass types, or interfaces

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

determines the operations an object can perform.

A

Type

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

determines the implementation of its methods

A

Class

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

is a side effect of Inheritance
and Typing

A

Polymorphism

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

___________________ for Flexibility: helps us write code
that is easy to modify and extend.

A

Polymorphism

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

it is the ability of the programming language to handle objects differently depending on their data type or class.

A

Polymorphism

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

Parametric Polymorphism

A

Java Generics

17
Q

Java ArrayList Methods

A

ArrayList <Integer> integers = new ArrayList<Integer>();</Integer></Integer>

integers.add();
integers.remove;
integers.get(index);
ingeters.size();
integers.isEmpty()
integers.addAll(Arrays.asList(1,2));

for (String s : stringList) //Iterate thru the elements

18
Q

Keyword for using an interface

A

implements

19
Q

Types of Polymorphism

A

True Polymorphism
- Subtype/Inclusion Polymorphism - A subclass of a superclass can be used as a substitute for its superclass.

  • Parametric Polymorphism - classes are written so generically that their methods can handle values identically without depending on their types.

Pseudo/Ad hoc Polymorphism
- Method overloading gives the illusion of parametric polymorphism.

20
Q

Example usage of Iterator Generic

A

Iterator <String> iter = stringList.iterator();</String>

while(iter.hasNext()){
Sysout(iter.next());
}

21
Q

Java HashMap
Methods

A

HashMap <Integer, String> studRec = new HashMap <Integer, String>();

studRec.put(202365908, “Myko”);

studRec.get(202365908)

//Check if key exists
studRec.containsKey(202365908)

//Returns all the keys
studRec.keySet();

22
Q

Narrowing conversions are possible if and only if the object came from a preceding widening
conversion.

A

TRUE