You are on page 1of 6

1Followin

. g good
program
ming
guideline
s, what
access
modifier
should
be used
for the
class
fields in
the
following
situation
?

Mark for Review


(1) Points

A car
insuranc
e
company
wants to
create a
class
named
Custome
r that
stores all
data for
a
specified
custome
r
including
the
fields:
vehicle
informati
on,
policy
informati
on, and
a credit
card
number.
Public
Protected
Private (*)
Default
All of the above
Correct
2. A team is working on a coding project. They desire that all portions of their
code should have access to the classes that they write. What access
modifier should be used for each class?

Mark for
Review

(1) Points
Public (*)
Protected
Private
Default
All of the above
Correct
3. Which of the following could be a reason to need to pass an object into a
method?

Mark for
Review
(1) Points

Easier access to the information contained within the object.


The ability to make changes to an object inside of the method.
Comparing two objects.
All of the above. (*)
Correct
4. Which of the following shows the correct way to initialize a method
DolphinTalk that takes in 2 integers, dol1 and dol2, and returns the greater
int between the two?

Mark for
Review
(1) Points

int DolphinTalk(dol1, dol2){ if(dol1 > dol2) return dol1; else return
dol2;}
int DolphinTalk(int,int){ if(dol1 > dol2) return dol1; else return dol2;}
int DolphinTalk(int dol1,int dol2){ if(dol1 > dol2) return dol1; else return
dol2;} (*)
int DolphinTalk, int dol1,int dol2 { if(dol1 > dol2) return dol1; else
return dol2;}
All of the above
Correct
5. Cameron wishes to write a method that takes in two objects and returns
the one with the greatest value. Is this possible?

Mark for
Review
(1) Points

Yes, but he will have to use two different methods, one to take in the
objects and the other to return an object.
Yes, methods can take objects in as parameters and can also return
objects all within the same method. (*)
No, it is not possible to return objects.
No, it is not possible to have objects as parameters or to return objects.

Correct
6. You are assigned to write a method that compares two objects of type
Career. One requirement of your assignment is to have your method
compare the "greatestPossibleSalary" instance data of Career objects. The
"greatestPossibleSalary" field is data type int.
What would be the best return type from your compare method?

Mark for
Review
(1) Points

Career, because if it returns the highest paying Career object it will be


able to use the same method later to compare other aspects of Career
objects. (*)
Integer, because it is the easiest to code with.
String, because is should return a string of the name of the career that
is highest paying because none of the other information of the career
matters.
Array, because it can store the most information.
Correct
7. Consider the following:
There is a method A that calls method B. Method B is a variable argument
method.
With this, which of the following are true?

Mark for
Review
(1) Points

(Choose all correct answers)


Method A can invoke method B twice, each time with a different
number of arguments. (*)
A compliler error will result since method B does not know how large an
array to create when it is invoked by method A.
When invoked, method B creates an array to store some or all of the
arguments passed to it from method A. (*)
All of the above.
Incorrect. Refer to Section 7 Lesson 2.
8. What type(s) would work for a variable argument method?

Mark for
Review
(1) Points

(Choose all correct answers)


Integers, Strings, and Booleans (*)
Constructors
Arrays (*)
Objects (*)
All of the above
Correct

9. It is possible to have more than one constructor with the same name in a
class, but they must have different parameters. True or false?

Mark for
Review
(1) Points

True (*)
False
Correct
10. Which of the following is a possible way to overload constructors?

Mark for
Review
(1) Points

(*)

Correct
11. It is possible to overload a method that is not a constructor. True or False?

Mark for
Review
(1) Points

True (*)
False
Correct
12. Identify the error(s) in the class below. Choose all that apply.

Mark for
Review
(1) Points

No method named min is defined. (*)


Two methods cannot have the same name.
The parameters must be the same for all methods with the same name.
Private cannot be used as an access modifier.
Final cannot be used as an access modifier.
Correct