Sunteți pe pagina 1din 5

Test: Passing Objects and Overloading Methods: Quiz

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

All of the above

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

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

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. (*)


4. Which of the following shows the correct way to initialize a method DolphinTalk Mark for
that takes in 2 integers, dol1 and dol2, and returns the greater int between the
two?
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.

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 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.

7. Consider the following: Mark for

There is a method A that calls method B. Method B is a variable argument


method. Review
(1) Points
With this, which of the following are true?

(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.

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

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

10Which of the following is a possible way to overload constructors? Mark for


.

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

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.

S-ar putea să vă placă și