Your SlideShare is downloading. ×
0
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Revisão OCPJP7 - Class Design (parte 02)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Revisão OCPJP7 - Class Design (parte 02)

53

Published on

Revisão OCPJP7 - Class Design (parte 02) - Questões e Respostas

Revisão OCPJP7 - Class Design (parte 02) - Questões e Respostas

Published in: Software, Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
53
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. OCPJP Objetivo: Java Class Design
  • 2. Questão Dado: 1. public class base { 2. protected int blipvert(int x) { return 333; } 3. } 4. class sub extends base { 5. // insert code here 6. } Quais 5 métodos inseridos independentemente na linha 5 irão compilar? (Escolha 5) a. public int blipvert(int x) { return 0; } b. private int blipvert(int x) { return 0; } c. private int blipvert(long x) { return 0; } d. protected long blipvert(int x) { return 0; } e. protected int blipvert(long x) { return 0; } f. protected long blipvert(long x) { return 0; } g. protected long blipvert(int x, int y) { return 0; }
  • 3. Questão Resolvida Dado: 1. public class base { 2. protected int blipvert(int x) { return 333; } 3. } 4. class sub extends base { 5. // insert code here 6. } Quais 5 métodos inseridos independentemente na linha 5 irão compilar? (Escolha 5) a. public int blipvert(int x) { return 0; } b. private int blipvert(int x) { return 0; } c. private int blipvert(long x) { return 0; } d. protected long blipvert(int x) { return 0; } e. protected int blipvert(long x) { return 0; } f. protected long blipvert(long x) { return 0; } g. protected long blipvert(int x, int y) { return 0; } Correto Correto Correto Correto Correto
  • 4. Questão Dado: 10. class Base { 11. void foo() { } 12. } 13. class Sub extends Base { 14. //insert method here 15. } Quais 3 métodos, inseridos individualmente na linha 14 completarão corretamente a classe Sub (Escolha 3) A. int foo() { /* more code here */ } B. void foo() { /* more code here */ } C. public void foo() { /* more code here */ } D. private void foo() { /* more code here */ } E. protected void foo() { /* more code here */ }
  • 5. Questão Resolvida Dado: 10. class Base { 11. void foo() { } 12. } 13. class Sub extends Base { 14. //insert method here 15. } Quais 3 métodos, inseridos individualmente na linha 14 completarão corretamente a classe Sub (Escolha 3) A. int foo() { /* more code here */ } B. void foo() { /* more code here */ } C. public void foo() { /* more code here */ } D. private void foo() { /* more code here */ } E. protected void foo() { /* more code here */ } Correto Correto Correto
  • 6. Questão 11. class Foo{ 12. public void process() { System.out.print("foo"); } 13. class Bar extends Foo { 14. public void process() throws IOException 15. { 16. System.out.print("Class bar"); 17. throw new IOException(); 18. } 19. public static void main(String[] args) { 20. try { new Bar().process(); } 21. catch (IOException e) { System.out.println("Not able to compete your request."); } 22. } Qual é o resultado? a. Exception b. A,B,Exception c. Compilation fails because of an error in line 20. d. Compilation fails because of an error in line 14. e. A NullPointerException is thrown at runtime.
  • 7. Questão Resolvida 11. class Foo{ 12. public void process() { System.out.print("foo"); } 13. class Bar extends Foo { 14. public void process() throws IOException 15. { 16. System.out.print("Class bar"); 17. throw new IOException(); 18. } 19. public static void main(String[] args) { 20. try { new Bar().process(); } 21. catch (IOException e) { System.out.println("Not able to compete your request."); } 22. } Qual é o resultado? a. Exception b. A,B,Exception c. Compilation fails because of an error in line 20. d. Compilation fails because of an error in line 14. e. A NullPointerException is thrown at runtime. Correto
  • 8. Questão Dado: 1. class BasePizza { 2. java.util.ArrayList toppings; 3. public final void addTopping(String topping) { 4. toppings.add(topping); 5. } 6. } 7. public class PepperoniPizza extends BasePizza { 8. public void addTopping(String topping) { 9. System.out.println("Toppings not available"); 10. } 11. public static void main(String[] args) { 12. BasePizza pizza = new PepperoniPizza(); 13. pizza.addTopping("Mushrooms"); 14. } 15. } Qual é o resultado? a. Compilation fails. b. Toppings not available. c. The code runs with no output. d. A NullPointerException is thrown in Line 4.
  • 9. Questão Resolvida Dado: 1. class BasePizza { 2. java.util.ArrayList toppings; 3. public final void addTopping(String topping) { 4. toppings.add(topping); 5. } 6. } 7. public class PepperoniPizza extends BasePizza { 8. public void addTopping(String topping) { 9. System.out.println("Toppings not available"); 10. } 11. public static void main(String[] args) { 12. BasePizza pizza = new PepperoniPizza(); 13. pizza.addTopping("Mushrooms"); 14. } 15. } Qual é o resultado? a. Compilation fails. b. Toppings not available. c. The code runs with no output. d. A NullPointerException is thrown in Line 4. Correto
  • 10. Questão Dado: 11. static class Foo { 12. void process() throws Exception { 13. System.out.println("Foo"); 14. throw new Exception(); } 15. } 16. static class Bar extends Foo { 17. void process() { System.out.println("Bar"); } 18. } 19. public static void main(String[ ] args) { 20. new Bar().process(); 21. } Qual é o resultado? A. Bar B. The code runs with no output. C. Compilation fails because of an error in line 12. D. Compilation fails because of an error in line 15 E. Compilation fails because of an error in line 18.
  • 11. Questão Resolvida Dado: 11. static class Foo { 12. void process() throws Exception { 13. System.out.println("Foo"); 14. throw new Exception(); } 15. } 16. static class Bar extends Foo { 17. void process() { System.out.println("Bar"); } 18. } 19. public static void main(String[ ] args) { 20. new Bar().process(); 21. } Qual é o resultado? A. Bar B. The code runs with no output. C. Compilation fails because of an error in line 12. D. Compilation fails because of an error in line 15 E. Compilation fails because of an error in line 18. Correto
  • 12. Questão Dado: 11. class Base { public void foo() { System.out.print("Base "); } } 12. 13. public class Sub extends Base { 14. public void foo() throws RuntimeException { 15. super.foo(); 16. if (true) throw new RuntimeException(); 17. System.out.print("Sub "); 18. } 19. public static void main(String[] args) { 20. new Sub().foo(); 21. } 22. } Qual é o resultado? a. Base, followed by an Exception. b. No output, and an Exception is thrown. c. Compilation fails due to an error on line 14. d. Compilation fails due to an error on line 16. e. Compilation fails due to an error on line 17. f. Base, followed by an Exception, followed by Sub.
  • 13. Questão Resolvida Dado: 11. class Base { public void foo() { System.out.print("Base "); } } 12. 13. public class Sub extends Base { 14. public void foo() throws RuntimeException { 15. super.foo(); 16. if (true) throw new RuntimeException(); 17. System.out.print("Sub "); 18. } 19. public static void main(String[] args) { 20. new Sub().foo(); 21. } 22. } Qual é o resultado? a. Base, followed by an Exception. b. No output, and an Exception is thrown. c. Compilation fails due to an error on line 14. d. Compilation fails due to an error on line 16. e. Compilation fails due to an error on line 17. f. Base, followed by an Exception, followed by Sub. Correto
  • 14. Questão Dado: 10. class One { 11. public One hello() { return this; } 12. } 13. class Two extends One { 14. public One hello() { return this; } 15. } 16. class Three extends Two { 17. // insert method here 18. } Quais 2 métodos que inseridos individualmente completam corretamente a classe Three? (Escolha 2) a. public void hello() {} b. public int hello() { return 3; } c. public Two hello() { return this; } d. public One hello() { return this; } e. public Object hello() { return this; }
  • 15. Questão Resolvida Dado: 10. class One { 11. public One hello() { return this; } 12. } 13. class Two extends One { 14. public One hello() { return this; } 15. } 16. class Three extends Two { 17. // insert method here 18. } Quais 2 métodos que inseridos individualmente completam corretamente a classe Three? (Escolha 2) a. public void hello() {} b. public int hello() { return 3; } c. public Two hello() { return this; } d. public One hello() { return this; } e. public Object hello() { return this; } Correto Correto
  • 16. Questão Dado: 10. class SuperCalc { 11. protected static int multiply(int i, int j) { return i* j;} 12. } e: 20. class SubCalc extends SuperCalc{ 21. public static int multiply(int i , int j) { 22. int ans = super.multiply(j, i); 23. return ans; 24. } 25. } e: 30. SubCalc sc = new SubCalc (); 31. System.out.println(sc.multiply(3,3)); 32. System.out.println(SubCalc.multiply(4,4)); Qual é o resultado? A. 9 16 B. The code runs with no output. C. An exception is thrown at runtime. D. Compilation fails because of an error in line 21. E. Compilation fails because of an error in line 22. F. Compilation fails because of an error in line 31.
  • 17. Questão Resolvida Dado: 10. class SuperCalc { 11. protected static int multiply(int i, int j) { return i* j;} 12. } e: 20. class SubCalc extends SuperCalc{ 21. public static int multiply(int i , int j) { 22. int ans = super.multiply(j, i); 23. return ans; 24. } 25. } e: 30. SubCalc sc = new SubCalc (); 31. System.out.println(sc.multiply(3,3)); 32. System.out.println(SubCalc.multiply(4,4)); Qual é o resultado? A. 9 16 B. The code runs with no output. C. An exception is thrown at runtime. D. Compilation fails because of an error in line 21. E. Compilation fails because of an error in line 22. F. Compilation fails because of an error in line 31. Correto
  • 18. Questão Dado: 1. class Super { 2. private int a; 3. protected Super(int a) { this.a = a; } 4. } ... 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { this.a = 5; } 14. } Quais 2 independentemente permitirão Sub compilar? (Escolha 2) a. Change line 2 to: public int a; b. Change line 2 to: protected int a; c. Change line 13 to: public Sub() { this(5); } d. Change line 13 to: public Sub() { super(5); } e. Change line 13 to: public Sub() { super(a); }
  • 19. Questão Ressolvida Dado: 1. class Super { 2. private int a; 3. protected Super(int a) { this.a = a; } 4. } ... 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { this.a = 5; } 14. } Quais 2 independentemente permitirão Sub compilar? (Escolha 2) a. Change line 2 to: public int a; b. Change line 2 to: protected int a; c. Change line 13 to: public Sub() { this(5); } d. Change line 13 to: public Sub() { super(5); } e. Change line 13 to: public Sub() { super(a); } Correto Correto
  • 20. Questão Dado: 10: public class Hello { 11: String greeting; 12: int value; 13. public Hello(){ 14. greeting+= “ world”; 15. } 16: public Hello(int value) { 17: this.value = value; 18: greeting = "Hello"; 19: super(); 20: } 21: } e: 30: Hello c = new Hello(5); 31: System.out.println(c.greeting); Qual é o resultado? a. Hello b. Hello world c. Compilation fails. d. Hello world 5 e. The code runs with no output. f. An exception is thrown at runtime.
  • 21. Questão Resolvida Dado: 10: public class Hello { 11: String greeting; 12: int value; 13. public Hello(){ 14. greeting+= “ world”; 15. } 16: public Hello(int value) { 17: this.value = value; 18: greeting = "Hello"; 19: super(); 20: } 21: } e: 30: Hello c = new Hello(5); 31: System.out.println(c.greeting); Qual é o resultado? a. Hello b. Hello world c. Compilation fails. d. Hello world 5 e. The code runs with no output. f. An exception is thrown at runtime. Correto

×