• Home
  • Textbooks
  • Java Programming
  • Using Methods

Java Programming

Joyce Farrell

Chapter 3

Using Methods - all with Video Answers

Educators


Section 1

Review Questions

Problem 1

Advantages to creating methods in addition to the main() method include all of the following except _____.
a. the main() method is easier to follow
b. all methods are prewritten, saving the programmer work
c. it is easier to determine the overall intent of statements encapsulated in the methods
d. methods are reusable

Check back soon!

Problem 2

In Java, methods must include all of the following except _____________.
a. a call to another method
b. a declaration
c. curly braces
d. a body

Check back soon!
00:46

Problem 3

All method declarations contain _____________.
a. arguments
b. one or more explicitly named access specifiers
c. parentheses
d. the keyword static

Arin Asawa
Arin Asawa
Numerade Educator

Problem 4

A public static method named computeSum() is located in ClassA. To call the method from within ClassB, use the statement _____________.
a. ClassA.computeSum();
b. ClassB(computeSum());
c. ComputeSum(ClassA);
d. You cannot call computeSum() from within ClassB.

Check back soon!

Problem 5

Which of the following method declarations is correct for a static method named displayFacts() if the method receives an int argument?
a. public static int displayFacts()
b. public void displayFacts(int data)
c. public static void displayFacts(int data)
d. public void displayFacts(static int)

Check back soon!

Problem 6

Which of the following method declarations is correct for a static method named computeSum() if the method receives two double arguments?
a. public static double, double computeSum()
b. public static void computeSum(double a, double b)
c. public int computeSum(double a, double b)
d. public static int computeSum(double a, b)

Check back soon!

Problem 7

The method with the declaration public static int aMethod(double d) is a method type of _____________.
a. static
b. int
c. double
d. You cannot determine the method type.

Check back soon!
02:03

Problem 8

Which of the following is a correct call to a method declared as public static void aMethod(char code)?
a. void aMethod();
b. void aMethod('V');
c. aMethod(char 'M');
d. aMethod('Q');

Willis James
Willis James
Numerade Educator
02:03

Problem 9

A method is declared as public static void showResults(double d, int i). Which of the following is a correct method call?
a. showResults(double d, int i);
b. showResults(12.2, 67);
c. showResults(4, 99.7);
d. Two of these are correct.

Willis James
Willis James
Numerade Educator

Problem 10

The method with the declaration public static char procedure(double d) has a method type of _____________.
a. public
b. static
c. char
d. double

Check back soon!
02:03

Problem 11

The method public static boolean testValue(int response) returns _____________.
a. no value
b. an int value
c. a boolean value
d. You cannot determine what is returned.

Ernest Castorena
Ernest Castorena
Numerade Educator

Problem 12

Which of the following could be the last legally coded line of a method declared as public static int getVal(double sum)?
a. return;
b. return 77;
c. return 2.3;
d. Any of these could be the last coded line of the method.

Check back soon!

Problem 13

In the method header public static boolean(int age), age is a(n) _____.
a. argument
b. parameter
c. return value
d. final value

Check back soon!
00:49

Problem 14

The code between a pair of curly braces in a method is a _____________.
a. function
b. brick
c. block
d. sector

Ernest Castorena
Ernest Castorena
Numerade Educator

Problem 15

When a block exists within another block, the blocks are _____________.
a. structured
b. illegal
c. sheltered
d. nested

Check back soon!
00:52

Problem 16

The portion of a program within which you can reference a variable is the variable’s _____________.
a. scope
b. space
c. domain
d. range

Yujie Wang
Yujie Wang
College of San Mateo

Problem 17

You can declare variables with the same name multiple times _____________.
a. within a statement
b. within a block
c. within a method
d. You never can declare multiple variables with the same name.

Check back soon!

Problem 18

Nonambiguous, overloaded methods must have the same _____________.
a. types of parameters
b. number of parameters
c. parameter names
d. name

Check back soon!

Problem 19

If a method is written to receive a double parameter, and you pass an int to the method, then the method will _____________.
a. work correctly; the int will be promoted to a double
b. work correctly; the parameter type will automatically become an int
c. execute but issue a warning
d. not work; an error message will be issued

Check back soon!

Problem 20

If a method is written to receive an int parameter, and you pass a double to the method, then the method will _____________.
a. work correctly; the double will be promoted to an int
b. work correctly, but the double might lose some data
c. execute but issue a warning
d. not work; an error message will be issued

Check back soon!