martedì 5 novembre 2013

Q32

Given:

public class Runner {
     public static String name = "unknown";
     public void start() {
          System.out.println(name);
     }
     public static void main(String[] args) {
          name = "Daniel";
          start();
     }
}

What is the result?

A.
Daniel


B.
Unknown


C.
It may print”unknown”or”Daniel”depending on the JVM implementation.


D.
Compilation fails.


E.
An exception is thrown at runtime.



Risposta E :

Stiamo cercando di fare un riferimento statico ad un metodo non statico :

Cannot make a static reference to the non-static method start() from the type Runner

1 commento: