SlideShare uma empresa Scribd logo
1 de 27
Baixar para ler offline
OCPJP
Objetivo: Java Class Design
Questão
Dado:
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.
Questão Resolvida
Dado:
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
Questão
Dado:
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; public
void 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; public
void cut () { /* code here */ } }
Questão Resolvida
Dado:
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; public
void 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; public
void cut () { /* code here */ } }
Correto
Correto
Questão
Qual 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.
Questão Resolvida
Qual 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
Questão
Dado:
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.
Questão Resolvida
Dado:
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
Questão
Dado:
1. public class Alpha {
2. protected int count(int x) { return 0; }
3. }
4. class Beta extends Alpha {
5. // insert code here
6. }
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; }
Questão Resolvida
Dado:
1. public class Alpha {
2. protected int count(int x) { return 0; }
3. }
4. class Beta extends Alpha {
5. // insert code here
6. }
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
Questão
Dado:
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); }
Questão Resolvida
Dado:
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
Questão
Dado:
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 */ }
Questão Resolvida
Dado:
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
Questão
Dado:
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; }
Questão Resolvida
Dado:
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
Questão
Dado:
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
Questão Resolvida
Dado:
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
Questão
Dado:
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;
Questão Resolvida
Dado:
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
Questão
Um 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 comando
java -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)
Questão Resolvida
Um 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 comando
java -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
Questão
Dado a seguinte estrutura de diretórios:
DemoProject
|--utilspkg
| |--Utils.java
|
|--classes
|--
E a invocação do seguinte comenado:
javac -d classes utilspkg/Utils.java
Assumindo 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.
Questão Resolvida
Dado a seguinte estrutura de diretórios:
DemoProject
|--utilspkg
| |--Utils.java
|
|--classes
|--
E a invocação do seguinte comenado:
javac -d classes utilspkg/Utils.java
Assumindo 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
Questão
Dado:
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
Questão Resolvida
Dado:
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

Mais conteúdo relacionado

Destaque

Day 1 The Bible - God's Very Word
Day 1   The Bible - God's Very WordDay 1   The Bible - God's Very Word
Day 1 The Bible - God's Very Word
kirkevan11
 
Act chps13 28
Act chps13 28Act chps13 28
Act chps13 28
boswells1
 
Screenwriting for Programmers
Screenwriting for ProgrammersScreenwriting for Programmers
Screenwriting for Programmers
trigger106
 
Day 2 Step 1 - Read It
Day 2   Step 1 - Read ItDay 2   Step 1 - Read It
Day 2 Step 1 - Read It
kirkevan11
 
Day 3 Step 2 - Understand It
Day 3   Step 2 - Understand ItDay 3   Step 2 - Understand It
Day 3 Step 2 - Understand It
kirkevan11
 

Destaque (16)

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)
 
Day 1 The Bible - God's Very Word
Day 1   The Bible - God's Very WordDay 1   The Bible - God's Very Word
Day 1 The Bible - God's Very Word
 
Act chps13 28
Act chps13 28Act chps13 28
Act chps13 28
 
Screenwriting for Programmers
Screenwriting for ProgrammersScreenwriting for Programmers
Screenwriting for Programmers
 
Revisão OCPJP7 - String Processing
Revisão OCPJP7 - String ProcessingRevisão OCPJP7 - String Processing
Revisão OCPJP7 - String Processing
 
Bullying
BullyingBullying
Bullying
 
Day 2 Step 1 - Read It
Day 2   Step 1 - Read ItDay 2   Step 1 - Read It
Day 2 Step 1 - Read It
 
Revisão OCPJP7 - Class Design (parte 01)
Revisão OCPJP7 - Class Design (parte 01)Revisão OCPJP7 - Class Design (parte 01)
Revisão OCPJP7 - Class Design (parte 01)
 
Tabela da liga, mata mata
Tabela da liga, mata mataTabela da liga, mata mata
Tabela da liga, mata mata
 
Day 3 Step 2 - Understand It
Day 3   Step 2 - Understand ItDay 3   Step 2 - Understand It
Day 3 Step 2 - Understand It
 
Revisão OCPJP7 - Class Design (parte 03)
Revisão OCPJP7 - Class Design (parte 03)Revisão OCPJP7 - Class Design (parte 03)
Revisão OCPJP7 - Class Design (parte 03)
 
Inspiratieboek incassoplein
Inspiratieboek incassopleinInspiratieboek incassoplein
Inspiratieboek incassoplein
 
Boter op je hoofd of bij de vis
Boter op je hoofd of bij de vis   Boter op je hoofd of bij de vis
Boter op je hoofd of bij de vis
 
Raku today
Raku todayRaku today
Raku today
 
Ai Weiwei
Ai  WeiweiAi  Weiwei
Ai Weiwei
 
Project report on Havmor ice-cream
Project report on Havmor ice-cream Project report on Havmor ice-cream
Project report on Havmor ice-cream
 

Semelhante a Revisão OCPJP7 - Class Design (parte 04)

AspectJ — Programação orientada a aspectos em Java
AspectJ — Programação orientada a aspectos em JavaAspectJ — Programação orientada a aspectos em Java
AspectJ — Programação orientada a aspectos em Java
elliando dias
 
Java introdução ao java
Java   introdução ao javaJava   introdução ao java
Java introdução ao java
Armando Daniel
 
Java aprendendo linguagem.ppt
Java aprendendo linguagem.pptJava aprendendo linguagem.ppt
Java aprendendo linguagem.ppt
Emerson Cardoso
 
[CLPE] Design patterns com c#
[CLPE] Design patterns com c#[CLPE] Design patterns com c#
[CLPE] Design patterns com c#
Felipe Pimentel
 

Semelhante a Revisão OCPJP7 - Class Design (parte 04) (20)

Plataforma de compiladores .NET (“Roslyn”), C# 6 e Visual Studio “14”
Plataforma de compiladores .NET (“Roslyn”), C# 6 e Visual Studio “14”Plataforma de compiladores .NET (“Roslyn”), C# 6 e Visual Studio “14”
Plataforma de compiladores .NET (“Roslyn”), C# 6 e Visual Studio “14”
 
AspectJ — Programação orientada a aspectos em Java
AspectJ — Programação orientada a aspectos em JavaAspectJ — Programação orientada a aspectos em Java
AspectJ — Programação orientada a aspectos em Java
 
Java introdução ao java
Java   introdução ao javaJava   introdução ao java
Java introdução ao java
 
Java5
Java5Java5
Java5
 
Refatoração de código com Capitão Nascimento versão completa
Refatoração de código com Capitão Nascimento versão completaRefatoração de código com Capitão Nascimento versão completa
Refatoração de código com Capitão Nascimento versão completa
 
Package logica pu
Package logica puPackage logica pu
Package logica pu
 
Git, GitHub e OO
Git, GitHub e OOGit, GitHub e OO
Git, GitHub e OO
 
Java aprendendo linguagem.ppt
Java aprendendo linguagem.pptJava aprendendo linguagem.ppt
Java aprendendo linguagem.ppt
 
Series lab
Series labSeries lab
Series lab
 
Java hidden features
Java hidden featuresJava hidden features
Java hidden features
 
Java hidden features
Java hidden featuresJava hidden features
Java hidden features
 
[Curso Java Basico - Exceptions] Aula 52: criando sua propria exception
[Curso Java Basico - Exceptions] Aula 52: criando sua propria exception[Curso Java Basico - Exceptions] Aula 52: criando sua propria exception
[Curso Java Basico - Exceptions] Aula 52: criando sua propria exception
 
Design OO
Design OODesign OO
Design OO
 
Plataforma de compiladores .NET, Visual Studio 2015, C# 6 e futuro C# 7
Plataforma de compiladores .NET,Visual Studio 2015, C# 6 e futuro C# 7Plataforma de compiladores .NET,Visual Studio 2015, C# 6 e futuro C# 7
Plataforma de compiladores .NET, Visual Studio 2015, C# 6 e futuro C# 7
 
Revisao OCPJP - Princípios OO
Revisao OCPJP - Princípios OORevisao OCPJP - Princípios OO
Revisao OCPJP - Princípios OO
 
Spring Capitulo 03
Spring Capitulo 03Spring Capitulo 03
Spring Capitulo 03
 
Clean code
Clean codeClean code
Clean code
 
Semana 10: Encapsulação, cópia de instâncias, igualdade de instâncias
Semana 10: Encapsulação, cópia de instâncias, igualdade de instânciasSemana 10: Encapsulação, cópia de instâncias, igualdade de instâncias
Semana 10: Encapsulação, cópia de instâncias, igualdade de instâncias
 
[CLPE] Design patterns com c#
[CLPE] Design patterns com c#[CLPE] Design patterns com c#
[CLPE] Design patterns com c#
 
Leonardo Zamariola - High Order Functions e Functional Interfaces
Leonardo Zamariola - High Order Functions e Functional InterfacesLeonardo Zamariola - High Order Functions e Functional Interfaces
Leonardo Zamariola - High Order Functions e Functional Interfaces
 

Revisão OCPJP7 - Class Design (parte 04)

  • 2. Questão Dado: 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.
  • 3. Questão Resolvida Dado: 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
  • 4. Questão Dado: 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; public void 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; public void cut () { /* code here */ } }
  • 5. Questão Resolvida Dado: 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; public void 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; public void cut () { /* code here */ } } Correto Correto
  • 6. Questão Qual 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.
  • 7. Questão Resolvida Qual 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
  • 8. Questão Dado: 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.
  • 9. Questão Resolvida Dado: 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
  • 10. Questão Dado: 1. public class Alpha { 2. protected int count(int x) { return 0; } 3. } 4. class Beta extends Alpha { 5. // insert code here 6. } 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; }
  • 11. Questão Resolvida Dado: 1. public class Alpha { 2. protected int count(int x) { return 0; } 3. } 4. class Beta extends Alpha { 5. // insert code here 6. } 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
  • 12. Questão Dado: 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); }
  • 13. Questão Resolvida Dado: 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
  • 14. Questão Dado: 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 */ }
  • 15. Questão Resolvida Dado: 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
  • 16. Questão Dado: 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; }
  • 17. Questão Resolvida Dado: 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
  • 18. Questão Dado: 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
  • 19. Questão Resolvida Dado: 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
  • 20. Questão Dado: 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;
  • 21. Questão Resolvida Dado: 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
  • 22. Questão Um 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 comando java -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)
  • 23. Questão Resolvida Um 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 comando java -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
  • 24. Questão Dado a seguinte estrutura de diretórios: DemoProject |--utilspkg | |--Utils.java | |--classes |-- E a invocação do seguinte comenado: javac -d classes utilspkg/Utils.java Assumindo 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.
  • 25. Questão Resolvida Dado a seguinte estrutura de diretórios: DemoProject |--utilspkg | |--Utils.java | |--classes |-- E a invocação do seguinte comenado: javac -d classes utilspkg/Utils.java Assumindo 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
  • 26. Questão Dado: 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
  • 27. Questão Resolvida Dado: 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