mercredi 3 mars 2010

Exercice certification SCJP initialisation

Exercice :




 

Given the following :

public class Test {

    private int myvar=3;
    public Test(int myvar) {

        if (myvar == 5) {
            myvar = 2;
        } else {
            myvar =3;
        }
    }

    public void show() {
        System.out.println("myvar:" + myvar);
    }

    public static void main(String[] args) {
        Test test = new Test(4);
        test.show();
    }
}



What is the result (choose one) :
A: myvar:2
B: myvar:3
C: myvar:4
D: myvar:5
E: Compilation fails
F: An exception is thrown at runtime










Solution :



La solution est B myvar:3.pas facile ....

Aucun commentaire:

Enregistrer un commentaire