Week 3 Part 2 Flashcards

1
Q

When a parameter is passed to a method, it is known as

A

an argument

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

Classes that are compiled in the same directory are considered to be in the same _______

A

package

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

Most classes in Java programs need to be imported __________, by typing ______ followed by the class name

A

explicitly, import

think import java.utl

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

Classes that are in the same package, are they imported explicitly or implicitly?

A

Implicitly

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

For classes, what other situation is there where an import declaration is not required?

A

Not required if the class is referred to with a full qualified method name, including its package and class names.

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

Describe UML design. How many compartments? Where is the class name? Where are the class attributes? What are attributes? Where are the class operations? What are class operations?

A

3 compartments, class name in the top one. Class attributes in the second, which correspond to instance variables. Class operations in the third, which correspond to methods and constructors.

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

How are instance variables represented in UML?

A

-name:type

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

How are operations represented in UML?

A setter for example

A

+setName(name:type)

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

Apparently everything you learned in semester 1 is wrong. In UML do operations that don’t have a return type have a return value? (void)

A

Apparently not. If they do have return value it looks like this +getName():type

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

What happens if a class does not define constructors? What happens to the classes instance variables if this is the case?

A

The compiler provides a default constructor with no params. The instance vars are initialized to their default values

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

T/F - A default constructor will still be created if there is a declared constructor

A

False

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

T/F - Java requires a constructor call for every object that is created

A

True

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

T/F - Constructors specify return types

A

False

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

How does UML distinguish a constructor from class operations?

A

Places the word constructor between Guillemets “&laquo_space;»” pronounced GILL MITTS

«constructor»Account(name:type)

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

How does a compiler select the appropriate method to call when there’s overloading? What is this called? Explain the mechanisms behind this function

A

Inspects the:

number of arguments
types of arguments
order of arguments

It’s called the Method signature

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

test (float, int)
test (int, float)

Will it work?

A

Yes, they’re in a different order

17
Q

If 2 method have a different return type but the same arguments, will method overloading occur?

A

No, that would invalid method overloading

18
Q

What are 2 advantages on method overloading?

A

Flexibility, readability

19
Q

Used to implement an object in different ways

A

Constructor overloading

20
Q

Like method overloading, how does the compiler select the correct constructor?

A

Inspects the methods signature

21
Q

4 advantages of constructor overloading

A
  1. Can create new objects when you have differing amounts of data to pass
  2. Variety of way to create an object
  3. When adding a constructor, the compiler will not add a default no-arg constructor
  4. A constructor eliminates calling the normal or ordinary method implicitly
22
Q

What is constructor chaining? Can you have constructor chaining with no overloaded constructors?

A

When a call to a constructor is made from inside another constructor in the same class. This makes constructor chaining w/ no overloaded constructors impossible.

23
Q

3 benefits of constructor chaining

ACE

A
  1. Avoids code duplication
  2. Consistent Usage
  3. Ease of maintenance
24
Q

What term do we use for constructor chaining? What is notable about it?

A

this(). Has to be the first line in the constructor.

25
Q

Can every constructor utilize this()? What does it represent?

A

No, at least one must not have it. this() represents an object being constructed.

26
Q

Is there is a restricted order to chaining?

A

No, chaining can be realized in any given order.