Return to site

JAVA CERTIFICATION QUESTION: Correctly apply the static keyword to methods and fields 🥇👩‍💻👨‍💻

=>Test your knowledge of static fields in Java.

· java

The objective of this Java SE 11 quiz is to apply the static keyword to methods and fields.

Given that this code is compiled:

class TestRunner {  
  static public int succeeded;
  static public int failed;
  
  public TestRunner() {    
  }
  
  public TestRunner(int s, int f) {
    succeeded=s; failed=f;
  }
  
  public String toString() {
      return succeeded + " " + failed;
  }
}

class TestStatistics {
  public static void main(String[] args) {
    TestRunner tr = new TestRunner(1, 99);
    TestRunner.succeeded = 99;
    System.out.print(new TestRunner());
  }
}

And is run as:

java TestStatistics

What is the output? Choose one.

A. 0 0

B. 1 99

C. 99 0

D. 99 99

 

ꓷ sᴉ ɹǝʍsuɐ ʇɔǝɹɹoɔ ǝɥꓕ