Quiz #2 review Flashcards

1
Q

What are the three types of relationships that can exist between object?

A

Inheritance, Containment, and Polymorphism

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

Inheritance definition

A

“inheriting” code from an already created class. Allows user to add on features to starting classes

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

Which = “is-a” relationship

A

Inheritance; sailboat is a boat

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

Containment definition

A

“has-a” relationship; car has-a engine

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

Base Class vs Derived Class

A

Base class is the starting class while the derived class inherits from the base class

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

Object superclass properties

A

cannot be inherited from

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

Object superclass methods

A

Equals, clone, toString

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

overriding definition

A

child class has the same method as the parent class

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

overloading definition

A

When a class contains two methods with the same name, but one has constructors while the other acts as the no-args constructor

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

Be able to set up the constructor for a derived class and use the super keyword

A

Be able to set up the constructor for a derived class and use the super keyword

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

Be able to draw an inheritance hierarchy diagram

A

Be able to draw an inheritance hierarchy diagram

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

How do you add inheritance or containment to a class?

A

Class extends subclass

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

Differences between private, protected, public, and no access

A

private can only be accessed by the class, protected can be accessed by the parent class and child classes, public can be accessed by anyone, and no access means nothing has access. No modifier means any file in the current directory may access

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

private

A

can only be accessed by the class its contained in

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

protected

A

can only be accessed by the parent class and any child classes

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

public

A

anyone can use

17
Q

no access

A

no access

18
Q

no public/private etc,

A

can be accessed by any file in the same directory

19
Q

Polymorphism definition

A

when a program is running, you send off a child object as a parent object and you want the parent object to act like a child

20
Q

When does a ClassCastException occur

A

When you try to send a parent object into a child

21
Q

abstract classes definition

A

very general class that’s built to be inherited from. Defines methods with abstract keyword, but does not fill in body.
Any class that inherits must have all abstract methods defined.
Must have at least 1 abstract method

22
Q

final classes definition

A

opposite of abstract classes.
can never be inherited from.
extends is forbidden.
will never be a “is-a”

23
Q

Interfaces definition

A

purely abstract class.
never has variables.
all methods are abstract be default.

24
Q

When should you use abstract classes?

A

When a class is very generic

25
Q

abstract classes examples

A

vehicle, shape.

26
Q

Can you have multiple classes in the same file?

A

Yes. however only 1 can/must be public

27
Q

Can you have nested classes?

A

yes

28
Q

BitSet definition

A

Array of booleans

29
Q

when are interfaces used?

A

when creating GUIs

30
Q

Definition of Listener Objects

A

calls to a method when the user interacts with the program (ex. press a button)

31
Q

What is an inner class?

A

a class nested inside another class

32
Q

Can an object of an inner class type be instantiated?

A

Not unless the outer class is fist instantiated

33
Q

What is the default layout
manager for a window?

A

BorderLayout

34
Q

What are the most common layout manager classes

A

Grid, flow, border

35
Q

Recursion vs iteration

A

Iteration is a method using a standard loop, while recursion calls upon itself to loop

36
Q

Advantage and disadvantages of recursion compared to iteration

A

recursion more elegant
easier to debug
uses more memory

37
Q

example of infinite recursion

A

calling upon the main method

38
Q

Throwable

A

superclass for all exception classes, and is where the getMessage() method is defined