Excessões - o que imprime?

4 respostas
ricardolecheta

What is the result of attempting to compile and run the program?

a. Prints: 1,0,0,0,0,0
b. Prints: 1,0,1,0,0,1
c. Prints: 0,0,1,0,0,1
d. Prints: 1,1,1,1,1,1
e. Compiler Error
f. Run Time Error
g. None of the Above

class Level1Exception extends Exception {}
class Level2Exception extends Level1Exception {}
class Level3Exception extends Level2Exception {}
class Purple {
  public static void main(String args[]) {
    int a,b,c,d,f,g,x;
    a = b = c = d = f = g = 0;
    x = 5;
    try {
      try {
	         switch (x) {
             case 1: throw new Level1Exception();
             case 2: throw new Level2Exception();
             case 3: throw new Level3Exception();
             case 4: throw new Exception();
        }
        a++;
      }
      catch (Level2Exception e) {b++;}
      finally{c++;}
    }
    catch (Level1Exception e) { d++;}
    catch (Exception e) {f++;}
    finally {g++;}
    System.out.print(a+","+b+","+c+","+d+","+f+","+g);
  }
}

4 Respostas

Ironlynx

Letra B?

B

Acho que é a letra b = 1,0,1,0,0,1
porque não vai lançar nenhuma exceção, só os incrementados das clausulas finally que serão executados

Acho q é isso

:slight_smile:

luiz_ross

Acho que a letra b é a correta!!

ricardolecheta

isso mesmo! :smiley:

Criado 12 de agosto de 2003
Ultima resposta 13 de ago. de 2003
Respostas 4
Participantes 4