Calling Class Methods MCQ Practice

Question 1 of 10

Which keyword in a method header identifies a class method?

  1. A. instance
  2. B. static
  3. C. classCall
  4. D. construct

Question 2 of 10

Class TramCar defines public static int seats(). Which call from a different class is correct?

  1. A. seats.TramCar()
  2. B. TramCar.seats()
  3. C. new seats()
  4. D. TramCar seats()

Question 3 of 10

Does calling an accessible class method normally require constructing an object first?

  1. A. Yes, every method call needs new.
  2. B. No, a class method is called through the class name.
  3. C. Yes, but only if the method returns void.
  4. D. No, but only if the method name is seats.

Question 4 of 10

TramCar is documented below. What value does cap hold?

Member Kind Contract
seats class method returns 24
load class method returns 24 plus the given standing int
int cap = TramCar.load(6);
  1. A. 24
  2. B. 6
  3. C. 30
  4. D. The code cannot compile without new TramCar().

Question 5 of 10

TramCar.seats() returns 24. What value does mixed hold?

int mixed = TramCar.seats() - 4;
  1. A. 24
  2. B. 4
  3. C. 20
  4. D. 244

Question 6 of 10

These methods are both in class TramCar. What value does TramCar.full() return?

public static int seats()
{
    return 24;
}
public static int full()
{
    return seats() + 8;
}
  1. A. 24
  2. B. 8
  3. C. 32
  4. D. The code cannot compile because seats needs TramCar.seats().

Question 7 of 10

Class Depot does not define seats. TramCar defines public static int seats() returning 24. Which statement about this Depot code is true?

int n = seats();
  1. A. It stores 24.
  2. B. It does not compile; Depot must write TramCar.seats().
  3. C. It stores 0.
  4. D. It prints 24 automatically.

Question 8 of 10

TramCar.cars() returns 3 and TramCar.total(int n) returns n * 24. What value is displayed?

System.out.print(TramCar.total(TramCar.cars()));
  1. A. 3
  2. B. 24
  3. C. 72
  4. D. 324

Question 9 of 10

TramCar.bell() is public static void and prints CLANG. What text is displayed?

System.out.print("GO");
TramCar.bell();
System.out.print("STOP");
  1. A. CLANG
  2. B. GOSTOP
  3. C. GOCLANGSTOP
  4. D. GOCLANG

Question 10 of 10

TramCar.load(int standing) returns 24 + standing. What value is displayed?

int standing = 5;
TramCar.load(standing);
System.out.print(standing);
  1. A. 29
  2. B. 24
  3. C. 5
  4. D. 0