SlideShare a Scribd company logo
OCPJP
Objetivo: Java Class Design
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; }
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
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 */ }
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
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.
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
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.
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
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.
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
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.
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
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; }
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
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.
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
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); }
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
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.
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

More Related Content

PDF
Scjp6.0
PDF
Revisão OCPJP7 - Class Design (parte 03)
DOCX
Simulado java se 7 programmer
PDF
1z0 851 exam-java standard edition 6 programmer certified professional
PPTX
SoCal Code Camp 2015: An introduction to Java 8
PDF
Improving Java performance at JBCNConf 2015
PDF
E5
Scjp6.0
Revisão OCPJP7 - Class Design (parte 03)
Simulado java se 7 programmer
1z0 851 exam-java standard edition 6 programmer certified professional
SoCal Code Camp 2015: An introduction to Java 8
Improving Java performance at JBCNConf 2015
E5

What's hot (20)

PDF
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
PDF
TDD CrashCourse Part4: Improving Testing
PDF
Fnt software solutions placement paper
PDF
ES3-2020-07 Testing techniques
PPSX
C# 6.0 - April 2014 preview
PPTX
12. Java Exceptions and error handling
PPT
Java Inheritance
PPT
Java language fundamentals
DOC
Final JAVA Practical of BCA SEM-5.
PPT
Exceptions
PPTX
20.4 Java interfaces and abstraction
PDF
Improving Android Performance at Droidcon UK 2014
PDF
The Ring programming language version 1.6 book - Part 184 of 189
DOCX
C++ lab assignment
PPT
E:\Plp 2009 2\Plp 9
KEY
Inside PyMongo - MongoNYC
PPT
Csphtp1 05
KEY
Minicurso de TestesOnRails
PPTX
An other world awaits you
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...
TDD CrashCourse Part4: Improving Testing
Fnt software solutions placement paper
ES3-2020-07 Testing techniques
C# 6.0 - April 2014 preview
12. Java Exceptions and error handling
Java Inheritance
Java language fundamentals
Final JAVA Practical of BCA SEM-5.
Exceptions
20.4 Java interfaces and abstraction
Improving Android Performance at Droidcon UK 2014
The Ring programming language version 1.6 book - Part 184 of 189
C++ lab assignment
E:\Plp 2009 2\Plp 9
Inside PyMongo - MongoNYC
Csphtp1 05
Minicurso de TestesOnRails
An other world awaits you
Ad

Viewers also liked (12)

PPT
7.1. procedimientos almacenados
PPTX
Ambiguty
PPT
computer architecture.
PPT
Lexical Analyzers and Parsers
PPTX
I/O Buffering
PPT
5. spooling and buffering
PPTX
Error detection recovery
PPT
Error detection and correction
PPTX
Role-of-lexical-analysis
PPTX
Input-Buffering
PPTX
Recognition-of-tokens
PPT
Error Detection And Correction
7.1. procedimientos almacenados
Ambiguty
computer architecture.
Lexical Analyzers and Parsers
I/O Buffering
5. spooling and buffering
Error detection recovery
Error detection and correction
Role-of-lexical-analysis
Input-Buffering
Recognition-of-tokens
Error Detection And Correction
Ad

Similar to Revisão OCPJP7 - Class Design (parte 02) (20)

TXT
Indus Valley Partner aptitude questions and answers
PDF
Oop Presentation
PDF
Core java
PPTX
Hybrid inheritance
PPTX
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
PDF
1z0 804 exam-java se 7 programmer ii
PPTX
Java concurrency questions and answers
PPTX
Technical aptitude test 2 CSE
DOCX
Multiple Choice Questions for Java interfaces and exception handling
PDF
2 object orientation-copy
PPTX
Java Quiz
PPTX
Language fundamentals ocjp
DOCX
Wap to implement bitwise operators
DOCX
FSOFT - Test Java Exam
PDF
C# programs
DOCX
Comp 328 final guide
PDF
T1
PPTX
Java SE 17 Study Guide for Certification - Chapter 01
PDF
[C++ Korea] Effective Modern C++ Study, Item 11 - 13
Indus Valley Partner aptitude questions and answers
Oop Presentation
Core java
Hybrid inheritance
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
1z0 804 exam-java se 7 programmer ii
Java concurrency questions and answers
Technical aptitude test 2 CSE
Multiple Choice Questions for Java interfaces and exception handling
2 object orientation-copy
Java Quiz
Language fundamentals ocjp
Wap to implement bitwise operators
FSOFT - Test Java Exam
C# programs
Comp 328 final guide
T1
Java SE 17 Study Guide for Certification - Chapter 01
[C++ Korea] Effective Modern C++ Study, Item 11 - 13

More from Julio Cesar Nunes de Souza (7)

PDF
Introdução AngularJS 4 com CLI
PDF
Visão geral sobre Assertivas e Exceções no Java7
ODP
"Mas eu não tenho experiência..." E daí??? - Como quebrar o ciclo vicioso de...
PDF
Revisao OCPJP - Princípios OO
PDF
Revisão OCPJP7 - String Processing
PDF
Revisão OCPJP7 - Class Design (parte 04)
PDF
Revisão OCPJP7 - Class Design (parte 01)
Introdução AngularJS 4 com CLI
Visão geral sobre Assertivas e Exceções no Java7
"Mas eu não tenho experiência..." E daí??? - Como quebrar o ciclo vicioso de...
Revisao OCPJP - Princípios OO
Revisão OCPJP7 - String Processing
Revisão OCPJP7 - Class Design (parte 04)
Revisão OCPJP7 - Class Design (parte 01)

Recently uploaded (20)

PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
L1 - Introduction to python Backend.pptx
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Digital Strategies for Manufacturing Companies
PPTX
Introduction to Artificial Intelligence
PPTX
history of c programming in notes for students .pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Nekopoi APK 2025 free lastest update
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
How to Choose the Right IT Partner for Your Business in Malaysia
Upgrade and Innovation Strategies for SAP ERP Customers
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03
L1 - Introduction to python Backend.pptx
2025 Textile ERP Trends: SAP, Odoo & Oracle
How to Migrate SBCGlobal Email to Yahoo Easily
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Digital Strategies for Manufacturing Companies
Introduction to Artificial Intelligence
history of c programming in notes for students .pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Nekopoi APK 2025 free lastest update
Design an Analysis of Algorithms I-SECS-1021-03
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
wealthsignaloriginal-com-DS-text-... (1).pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Odoo POS Development Services by CandidRoot Solutions
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Navsoft: AI-Powered Business Solutions & Custom Software Development

Revisão OCPJP7 - Class Design (parte 02)

  • 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