Professional Documents
Culture Documents
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Section 1
(Answer all questions in this section)
1. Following good programming guidelines, what access modifier should be used for
the class fields in the following situation?
A car insurance company wants to create a class named Customer that stores all
data for a specified customer including the fields: vehicle information, policy
information, and a credit card number.
Mark for
Review
(1) Points
Public
Protected
Private (*)
Default
All of the above
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
3. Which of the following could be a reason to need to pass an object into a method?
Mark for
Review
(1) Points
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
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.
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.
Mark for
method.
With this, which of the following are true?
Review
(1) Points
Mark for
Review
(1) Points
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
Mark for
Review
(1) Points
(*)
Mark for
Review
(1) Points
True (*)
False
12Identify the error(s) in the class below. Choose all that apply.
.
Mark for
Review
(1) Points