Documente Academic
Documente Profesional
Documente Cultură
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 Mark for
the class fields in the following situation?
A car insurance company wants to create a class named Customer that stores all Review
data for a specified customer including the fields: vehicle information, policy (1) Points
information, and a credit card number.
Public
Protected
Private (*)
Default
2. A team is working on a coding project. They desire that all portions of their code Mark for
should have access to the classes that they write. What access modifier should be
used for each class?
Review
(1) Points
Public (*)
Protected
Private
Default
3. Which of the following could be a reason to need to pass an object into a method? 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 Mark for
with the greatest value. Is this possible?
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.
6. You are assigned to write a method that compares two objects of type Career. One Mark for
requirement of your assignment is to have your method compare the
"greatestPossibleSalary" instance data of Career objects. The
"greatestPossibleSalary" field is data type int. Review
(1) Points
What would be the best return type from your compare method?
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.
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.
8. What type(s) would work for a variable argument method? Mark for
Review
(1) Points
Constructors
Arrays (*)
Objects (*)
9. It is possible to have more than one constructor with the same name in a class, Mark for
but they must have different parameters. True or false?
Review
(1) Points
True (*)
False
Review
(1) Points
(*)
11It is possible to overload a method that is not a constructor. True or False? Mark for
.
Review
(1) Points
True (*)
False
12Identify the error(s) in the class below. Choose all that apply. Mark for
.
Review
(1) Points
The parameters must be the same for all methods with the same name.