Method Signatures MCQ Practice

Question 1 of 10

A harbor class contains this method header. What is its Java method signature?

public static boolean dockOpen(int hour, boolean storm)
  1. A. dockOpen(hour, storm)
  2. B. boolean dockOpen(int, boolean)
  3. C. dockOpen(int, boolean)
  4. D. public dockOpen(int, boolean)

Question 2 of 10

A buoy controller documents only the methods below. A keeper must record channel 12 and whether the lamp is on. Which method should be selected?

Header Purpose
public static void ping() flashes the lamp once
public static void ping(int times) flashes the lamp that many times
public static void tag(int channel, boolean lit) records a channel number and lamp state
public static double waitTime(double km) returns minutes to reach a distance
  1. A. ping()
  2. B. ping(int)
  3. C. tag(int, boolean)
  4. D. waitTime(double)

Question 3 of 10

These headers are in the same class. Which header is used by the call trim(8, 0.5)?

public static void trim(double slack)
public static void trim(int line, double slack)
  1. A. trim(double), because 8 can widen to double
  2. B. trim(int, double), because the arguments are an int then a double
  3. C. Neither header, because the types are reversed
  4. D. A hidden trim(double, int) header

Question 4 of 10

A tide API lists fill(double, int) and fill(int, double). Which statement is true about the call fill(2, 3.5)?

  1. A. The call matches fill(double, int) because 3.5 is a double.
  2. B. The two headers have the same signature, so either may run.
  3. C. The call matches fill(int, double) because the argument types are int then double.
  4. D. The return type, not the parameter order, decides which method runs.

Question 5 of 10

The methods below are in the same class. What text does this Java code display?

public static void clang()
{
    System.out.print("GONG");
}

System.out.print("START");
clang();
System.out.print("END");
  1. A. GONG
  2. B. STARTEND
  3. C. STARTGONGEND
  4. D. STARTGONG

Question 6 of 10

The methods below are in the same class. What value is displayed?

public static void lift(int tide)
{
    tide = tide + 9;
}

int water = 14;
lift(water);
System.out.print(water);
  1. A. 23
  2. B. 14
  3. C. 9
  4. D. 0

Question 7 of 10

The methods below are in the same class. What value is displayed?

public static int lift(int tide)
{
    tide = tide + 9;
    return tide;
}

int water = 14;
water = lift(water);
System.out.print(water);
  1. A. 14
  2. B. 9
  3. C. 23
  4. D. 0

Question 8 of 10

The methods below are in the same class. What value is displayed?

public static int crate(int n)
{
    return n + 1;
}
public static int crate(int n, int extra)
{
    return n + extra;
}

System.out.print(crate(10, 4));
  1. A. 11
  2. B. 14
  3. C. 10
  4. D. 4

Question 9 of 10

The methods below are in the same class. What value is displayed?

public static int lift(int tide)
{
    tide = tide + 9;
    return tide;
}

int water = 14;
lift(water);
System.out.print(water);
  1. A. 23
  2. B. 14
  3. C. 9
  4. D. The code cannot compile.

Question 10 of 10

The methods below are in the same class. What is the result of this code?

public static void clang()
{
    System.out.print("GONG");
}

int n = clang();
  1. A. n stores 0.
  2. B. n stores the text GONG.
  3. C. The code cannot compile.
  4. D. n stores 4.