+ All Categories
Home > Software > Revisão OCPJP7 - Class Design (parte 04)

Revisão OCPJP7 - Class Design (parte 04)

Date post: 26-May-2015
Category:
Upload: julio-souza
View: 52 times
Download: 1 times
Share this document with a friend
Description:
Revisão OCPJP7 - Class Design (parte 04) - Questões e Respostas
Popular Tags:
27
OCPJP Objetivo: Java Class Design
Transcript
Page 1: Revisão OCPJP7 - Class Design (parte 04)

OCPJPObjetivo: Java Class Design

Page 2: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:

1. class Alcohol { 2. public void consume() { System.out.println("alcohol "); } 3. } 4. public class Beer extends Alcohol { 5. public void consume() { System.out.println("beer "); } 6. public static void main(String[] args) { 7. ((Alcohol)new Beer()).consume();8. }9. }

Qual é o resultado?

A. alcohol

B. beer

C. Compilation fails.

D. An exception is thrown at runtime.

Page 3: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:

1. class Alcohol { 2. public void consume() { System.out.println("alcohol "); } 3. } 4. public class Beer extends Alcohol { 5. public void consume() { System.out.println("beer "); } 6. public static void main(String[] args) { 7. ((Alcohol)new Beer()).consume();8. }9. }

Qual é o resultado?

A. alcohol

B. beer

C. Compilation fails.

D. An exception is thrown at runtime.

Correto

Page 4: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:11. public abstract class Tree { 12. private int height; 13. public abstract void cut(); 14. public void calculateAge(int height) { 15. System.out.println(height/10); 16. } 17. }

Quais duas classes usam a classe Three corretamente? (Escolha 2 opções)

A. public class MangoTree implements Tree { private int numberOfMangoes; }

B. public abstract class MangoTree extends Tree { private int numberOfMangoes; }

C. public class MangoTree extends Tree { private int numberOfMangoes; public void cut (); }

D. public abstract class MangoTree implements Tree { private int numberOfMangoes; publicvoid cut (); }

E. public class MangoTree extends Tree { private int numberOfMangoes; public void cut (){/* code here */} }

F. public abstract class MangoTree implements Tree { private int numberOfMangoes; publicvoid cut () { /* code here */ } }

Page 5: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:11. public abstract class Tree { 12. private int height; 13. public abstract void cut(); 14. public void calculateAge(int height) { 15. System.out.println(height/10); 16. } 17. }

Quais duas classes usam a classe Three corretamente? (Escolha 2 opções)

A. public class MangoTree implements Tree { private int numberOfMangoes; }

B. public abstract class MangoTree extends Tree { private int numberOfMangoes; }

C. public class MangoTree extends Tree { private int numberOfMangoes; public void cut (); }

D. public abstract class MangoTree implements Tree { private int numberOfMangoes; publicvoid cut (); }

E. public class MangoTree extends Tree { private int numberOfMangoes; public void cut (){/* code here */} }

F. public abstract class MangoTree implements Tree { private int numberOfMangoes; publicvoid cut () { /* code here */ } }

Correto

Correto

Page 6: Revisão OCPJP7 - Class Design (parte 04)

QuestãoQual afirmação é falsa?

A. A virtual method can be abstract.

B. A virtual method must be an instance method.

C. A virtual method can be final.

D. All methods in an interface are non-virtual.

Page 7: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaQual afirmação é falsa?

A. A virtual method can be abstract.

B. A virtual method must be an instance method.

C. A virtual method can be final.

D. All methods in an interface are non-virtual.

Correto

Page 8: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:11. class IceCream { 12. public final void changeTemperature() { System.out.print(“Temperature is -18 degC”);} 14. } 15. public class Vanilla extends IceCream {16. public void changeTemperature() { System.out.print(“Temperature is 20 degC”);}17. public static void main(String[] args) {18. new IceCream().changeTemperature();19. }

Qual é a saída do programa acima?

A. Temperature is -18 degC

B. Temperature is 20 degC

C. An Exception is thrown at runtime.

D. Compilation fails.

Page 9: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:11. class IceCream { 12. public final void changeTemperature() { System.out.print(“Temperature is -18 degC”);} 14. } 15. public class Vanilla extends IceCream {16. public void changeTemperature() { System.out.print(“Temperature is 20 degC”);}17. public static void main(String[] args) {18. new IceCream().changeTemperature();19. }

Qual é a saída do programa acima?

A. Temperature is -18 degC

B. Temperature is 20 degC

C. An Exception is thrown at runtime.

D. Compilation fails. Correto

Page 10: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:1. public class Alpha {2. protected int count(int x) { return 0; }3. }4. class Beta extends Alpha {5. // insert code here6. }7.

Quais 5 métodos, inseridos independentemente na linha 5 irão compilar? (Escolha 5)

a. public int count(int x) { return 0; }

b. private int count(int x) { return 0; }

c. private int count(long x) { return 0; }

d. protected long count(int x) { return 0; }

e. protected int count(long x) { return 0; }

f. protected long count(long x) { return 0; }

g. protected long count(int x, int y) { return 0; }

Page 11: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:1. public class Alpha {2. protected int count(int x) { return 0; }3. }4. class Beta extends Alpha {5. // insert code here6. }7.

Quais 5 métodos, inseridos independentemente na linha 5 irão compilar? (Escolha 5)

a. public int count(int x) { return 0; }

b. private int count(int x) { return 0; }

c. private int count(long x) { return 0; }

d. protected long count(int x) { return 0; }

e. protected int count(long x) { return 0; }

f. protected long count(long x) { return 0; }

g. protected long count(int x, int y) { return 0; }

Correto

Correto

Correto

Correto

Correto

Page 12: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:

1. class Alpha {2. private int a;3. protected Alpha(int a) { this.a = a; }4. }11. class Beta extends Alpha {12. public Beta(int a) { super(a); }13. public Beta() { this.a = 5; }14. }

Quais 2 independentemente permitirão Beta 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 Beta() { this(5);

d. Change line 13 to: public Beta() { super(5); }

e. Change line 13 to: public Beta() { super(a); }

Page 13: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:

1. class Alpha {2. private int a;3. protected Alpha(int a) { this.a = a; }4. }11. class Beta extends Alpha {12. public Beta(int a) { super(a); }13. public Beta() { this.a = 5; }14. }

Quais 2 independentemente permitirão Beta 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 Beta() { this(5);

d. Change line 13 to: public Beta() { super(5); }

e. Change line 13 to: public Beta() { super(a); }

Correto

Correto

Page 14: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:class Birds {void sound() { }}class Parrot extends Birds {14. // insert method here}

Quais 3 métodos que inseridos individualmente na linha 14 vão completar corretamente a classe Parrot? (Escolha 3)

a. int sound() { /* more code here */ }

b. void sound() { /* more code here */ }

c. public void sound() { /* more code here */ }

d. private void sound() { /* more code here */ }

e. protected void sound() { /* more code here */ }

Page 15: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:class Birds {void sound() { }}class Parrot extends Birds {14. // insert method here}

Quais 3 métodos que inseridos individualmente na linha 14 vão completar corretamente a classe Parrot? (Escolha 3)

a. int sound() { /* more code here */ }

b. void sound() { /* more code here */ }

c. public void sound() { /* more code here */ }

d. private void sound() { /* more code here */ }

e. protected void sound() { /* more code here */ }

Correto

Correto

Correto

Page 16: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:abstract public class Vendor {protected abstract double getSalesAmount();public double getCommision() {return getSalesAmount() * 0.20;}}class Retailer extends Vendor {17. // insert method here}

Quais 2 métodos inseridos independentemente na linha 16 corretamente completam a classe ReTailer (Escolha 2)

a. double getSalesAmount() { return 1230.45; }

b. public double getSalesAmount() { return 1230.45; }

c. private double getSalesAmount() { return 1230.45; }

d. protected double getSalesAmount() { return 1230.45; }

Page 17: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:abstract public class Vendor {protected abstract double getSalesAmount();public double getCommision() {return getSalesAmount() * 0.20;}}class Retailer extends Vendor {17. // insert method here}

Quais 2 métodos inseridos independentemente na linha 16 corretamente completam a classe ReTailer (Escolha 2)

a. double getSalesAmount() { return 1230.45; }

b. public double getSalesAmount() { return 1230.45; }

c. private double getSalesAmount() { return 1230.45; }

d. protected double getSalesAmount() { return 1230.45; }

Correto

Correto

Page 18: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:

11. public interface Alpha {12. /* insert code here */ int status= 10;

Quais 3 são válidos na linha 12 (Escolha 3)

a. final

b. static

c. native

d. public

e. private

f. abstract

g. protected

Page 19: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:

11. public interface Alpha {12. /* insert code here */ int status= 10;

Quais 3 são válidos na linha 12 (Escolha 3)

a. final

b. static

c. native

d. public

e. private

f. abstract

g. protected

Correto

Correto

Correto

Page 20: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:1. package utils;2.3. public class Repetition {4. public static String repeat(String s) { return s + s; }5. }and given another class RepetitionDemo:1. public class RepetitionDemo {2. public static void main(String[] args) {3. System.out.println(repeat("string"));4. }5. }

Que código deveria ser inserido na linha de de RepetitionDemo.java para compilar e executar para exibir “stringstring”?

A. import utils.*;

B. static import utils.*;

C. import utils.Repetition.*;

D. static import utils.Repetition.*;

E. import utils.Repetition.repeat();

F. import static utils.Repetition.repeat;

G. static import utils.Repetition.repeat;

Page 21: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:1. package utils;2.3. public class Repetition {4. public static String repeat(String s) { return s + s; }5. }and given another class RepetitionDemo:1. public class RepetitionDemo {2. public static void main(String[] args) {3. System.out.println(repeat("string"));4. }5. }

Que código deveria ser inserido na linha de de RepetitionDemo.java para compilar e executar para exibir “stringstring”?

A. import utils.*;

B. static import utils.*;

C. import utils.Repetition.*;

D. static import utils.Repetition.*;

E. import utils.Repetition.repeat();

F. import static utils.Repetition.repeat;

G. static import utils.Repetition.repeat;

Correto

Page 22: Revisão OCPJP7 - Class Design (parte 04)

QuestãoUm usuarios UNIX chamado John quer substituir seu programa Pool por um novo, mas ele não tem certeza onde seu antigo está instalado.Atualmente John executa o programa iniciando-o de seu diretório home /home/john usando o comandojava -classpath /test:/home/john/downloads/*.jar games.Pool

O CLASSPATHestá setado para:/usr/lib:/home/john/classes:/opt/java/lib:/opt/java/lib/*.jar

Qual é a possível localização do arquivo Pool.class?

A. /test/Pool.class

B. /home/bob/Pool.class

C. /test/games/Pool.class

D. /usr/lib/games/ Pool.class

E. /home/bob/games/ Pool.class

F. inside jar file /opt/java/lib/Games.jar (with a correct manifest)

G. inside jar file /home/bob/downloads/Games.jar (with a correct manifest)

Page 23: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaUm usuarios UNIX chamado John quer substituir seu programa Pool por um novo, mas ele não tem certeza onde seu antigo está instalado.Atualmente John executa o programa iniciando-o de seu diretório home /home/john usando o comandojava -classpath /test:/home/john/downloads/*.jar games.Pool

O CLASSPATHestá setado para:/usr/lib:/home/john/classes:/opt/java/lib:/opt/java/lib/*.jar

Qual é a possível localização do arquivo Pool.class?

A. /test/Pool.class

B. /home/bob/Pool.class

C. /test/games/Pool.class

D. /usr/lib/games/ Pool.class

E. /home/bob/games/ Pool.class

F. inside jar file /opt/java/lib/Games.jar (with a correct manifest)

G. inside jar file /home/bob/downloads/Games.jar (with a correct manifest)

Correto

Page 24: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado a seguinte estrutura de diretórios:

DemoProject|--utilspkg| |--Utils.java||--classes|--

E a invocação do seguinte comenado:javac -d classes utilspkg/Utils.javaAssumindo que o diretório corrente é DemoProject, Qual é o resultado?

a. If the compile is successful, Utils.class is added to the utilspkg directory.

b. The compiler returns an invalid flag error.

c. If the compile is successful, Utils.class is added to the classes directory.

d. If the compile is successful, Utils.class is added to the DemoProject directory.

Page 25: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado a seguinte estrutura de diretórios:

DemoProject|--utilspkg| |--Utils.java||--classes|--

E a invocação do seguinte comenado:javac -d classes utilspkg/Utils.javaAssumindo que o diretório corrente é DemoProject, Qual é o resultado?

a. If the compile is successful, Utils.class is added to the utilspkg directory.

b. The compiler returns an invalid flag error.

c. If the compile is successful, Utils.class is added to the classes directory.

d. If the compile is successful, Utils.class is added to the DemoProject directory.

Correto

Page 26: Revisão OCPJP7 - Class Design (parte 04)

QuestãoDado:

1. package com.foo.app;2.3. public class TestMain {4. public static void main(String[] args) {}5. }

E TestMain existe em /apps/com/foo/app directory. Assumindo que o CLASSPATH está setado para "." (diretório corrente).

Quais 2 comando java executarão TestMain? (Escolha 2)

a. java TestMain if run from the /apps directory

b. java com.foo.app.TestMain if run from the /apps directory

c. java -classpath /apps com.foo.app.TestMain if run from any directory

d. java -classpath . TestMain if run from the /apps/com/foo/app directory

e. java -classpath /apps/com/foo/app:. TestMain if run from the /apps directory

f. java com.foo.app.TestMain if run from the /apps/com/foo/app directory

Page 27: Revisão OCPJP7 - Class Design (parte 04)

Questão ResolvidaDado:

1. package com.foo.app;2.3. public class TestMain {4. public static void main(String[] args) {}5. }

E TestMain existe em /apps/com/foo/app directory. Assumindo que o CLASSPATH está setado para "." (diretório corrente).

Quais 2 comando java executarão TestMain? (Escolha 2)

a. java TestMain if run from the /apps directory

b. java com.foo.app.TestMain if run from the /apps directory

c. java -classpath /apps com.foo.app.TestMain if run from any directory

d. java -classpath . TestMain if run from the /apps/com/foo/app directory

e. java -classpath /apps/com/foo/app:. TestMain if run from the /apps directory

f. java com.foo.app.TestMain if run from the /apps/com/foo/app directory

Correto

Correto


Recommended