Mathesis Concursos Baixar grátis
2023 Cesgranrio Sistemas · Infraestrutura Médio

Transpetro PSP 2023 · sup04 — questão 22

Considere as seguintes classes Java, que ocupam arquivos public class Err01 extends Exception { public Err01() { } public Err01(String m) { super(m); } } public class Err02 extends Err01 { public Err02() { } public Err02(String m) { super(m); } } Qual classe NÃO produzirá erros de compilação?

  1. A public class Main { public double m01(double a, double b) { try { if(a < 0) throw new Err01(); if(b < 0) throw new Err02(); if(b == 0) throw new Exception(); } catch(Err01 e) { System.out.println("a menor do que zero"); } return a / b; } public static void main(String[] args) throws Exception { Main m=new Main(); System.out.println( m.m01 (8.0, 4.0) ); } } separados:
  2. B public class Main { public double m01(double a, double b) { try { if(a < 0) throw new Err01(); if(b <= 0) throw new Err02(); } catch(Err02 e) { System.out.println("b menor ou igual } return a / b; } public static void main(String[] args) throws Exception { Main m=new Main(); System.out.println( m.m01 (8.0, 4.0) ); } }
  3. C public class Main { public double m01(double a, double b) { try { if(a < 0) throw new Err01(); if(b <= 0) throw new Err02(); } catch(Err01 e) { System.out.println("a menor do que zero"); } catch(Err02 e) { System.out.println("b menor ou igual } catch(Exception e) { System.out.println("b igual a zero"); } return a / b; } public static void main(String[] args) throws Exception { Main m=new Main(); System.out.println( m.m01 (8.0, 4.0) ); } } a zero"); a zero")
  4. D public class Main { public double m01(double a, double b) throws Err01 try { if(a < 0) throw new Err01(); if(b < 0) throw new Err02(); if(b == 0) throw new Exception(); } catch(Exception e) { System.out.println("b igual a zero"); } return a / b; } public static void main(String[] args) throws Exception { Main m=new Main(); System.out.println( m.m01 (8.0, 4.0) ); } }
  5. E public class Main { public double m01(double a, double b) throws Exception { try { if(a < 0) throw new Err01(); if(b <= 0) throw new Err02(); } catch(Err01 e) { System.out.println("a menor do que zero"); } catch(Err02 e) { System.out.println("b menor ou igual } return a / b; } public static void main(String[] args) throws Exception { Main m=new Main(); System.out.println( m.m01 (8.0, 4.0) ); } } { a zero")

Gabarito oficial

Alternativa D

public class Main { public double m01(double a, double b) throws Err01 try { if(a < 0) throw new Err01(); if(b < 0) throw new Err02(); if(b == 0) throw new Exception(); } catch(Exception e) { System.out.println("b igual a zero"); } return a / b; } public static void main(String[] args) throws Exception { Main m=new Main(); System.out.println( m.m01 (8.0, 4.0) ); } }

Por que a resposta é alternativa d?

No app, esta questão vem com a explicação completa: o dispositivo ou o conceito cobrado, por que o gabarito é alternativa d e onde está a pegadinha da Cesgranrio. São 1.934 explicações só em Transpetro, e 9.512 questões nos onze concursos do app.

Disponível noGoogle Play Em breve naApp Store

2 de 49 em Sistemas · Infraestrutura · Transpetro