Questão de TI - Desenvolvimento de Sistemas — Códigos em Java — CESGRANRIO 2023
- Código
- cg057575
- Banca
- CESGRANRIO
- Órgão
- TRANSPETRO
- Ano
- 2023
- Cargo
- PTNS ( )
Considere as seguintes classes Java, que ocupam arquivos separados:
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?
- Apublic 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) ); } }
- Bpublic 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 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) ); } }
- Cpublic 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 a zero"); } 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) ); } }
- Dpublic 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) ); } }
- Epublic 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(Err01 e) { System.out.println("a menor do que zero"); } catch(Err02 e) { System.out.println("b menor ou 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) ); } }