SlideShare uma empresa Scribd logo
1 de 21
Baixar para ler offline
OCPJP
Objetivo: Java Class Design
Questão
Dado:
package com.sun.scjp;
public class Geometry {
public static final double DIAMETER = 0.72; // kilometers
}
Quais 2 podem acessar o membro DIAMETER corretamente da classe Geometry? (Escola 2 opções)
A. import com.sun.scjp.Geometry;
public class Ground {
public double halfway {
return Geometry.DIAMETER/2.0; }
}
B. import static com.sun.scjp.Geometry;
public class Ground {
public double halfway {
return DIAMETER/2.0; }
}
C. import static com.sun.scjp.Geometry.*;
public class Ground {
public double halfway {
return DIAMETER/2.0; }
}
D. package com.sun.scjp;
public class Ground {
public double halfway {
return DIAMETER/2.0; }
}
Questão Resolvida
Dado:
package com.sun.scjp;
public class Geometry {
public static final double DIAMETER = 0.72; // kilometers
}
Quais 2 podem acessar o membro DIAMETER corretamente da classe Geometry? (Escola 2 opções)
A. import com.sun.scjp.Geometry;
public class Ground {
public double halfway {
return Geometry.DIAMETER/2.0; }
}
B. import static com.sun.scjp.Geometry;
public class Ground {
public double halfway {
return DIAMETER/2.0; }
}
C. import static com.sun.scjp.Geometry.*;
public class Ground {
public double halfway {
return DIAMETER/2.0; }
}
D. package com.sun.scjp;
public class Ground {
public double halfway {
return DIAMETER/2.0; }
}
Correto
Correto
Questão
As classes abaixo estão definidas em 2 arquivos separados
1. package processors;
2. public class ByteProcessor {
3. public static void process(byte[] b) { /* more code here */ }
4. }
1. package apps;
2. public class ByteApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
O que é necessário na linha 5 da classe ByteApp para usar o método da classe ByteProcessor?
a. process(bytes);
b. ByteProcessor.process(bytes);
c. processors.ByteProcessor.process(bytes);
d. ByteApp cannot use methods in ByteProcessor.
e. import processors.ByteProcessors.*; process(bytes);
Questão Resolvida
As classes abaixo estão definidas em 2 arquivos separados
1. package processors;
2. public class ByteProcessor {
3. public static void process(byte[] b) { /* more code here */ }
4. }
1. package apps;
2. public class ByteApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
O que é necessário na linha 5 da classe ByteApp para usar o método da classe ByteProcessor?
a. process(bytes);
b. ByteProcessor.process(bytes);
c. processors.ByteProcessor.process(bytes);
d. ByteApp cannot use methods in ByteProcessor.
e. import processors.ByteProcessors.*; process(bytes);
Correto
Questão
As classes abaixo estão definidas em 2 arquivos separados
1. package processors;
2. public class ByteProcessor {
3. private static void process(byte[] b) { /* more code here */ }
4. }
1. package apps;
2. public class ByteApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class ByteApp to use the process method of ByteProcessor?
a. process(bytes);
b. ByteProcessor.process(bytes);
c. apps.ByteProcessor.process(bytes);
d. processors.ByteProcessor.process(bytes);
e. import processors.ByteProcessor.*; process(bytes);
f. ByteApp cannot use the process method in ByteProcessor.
Questão Resolvida
As classes abaixo estão definidas em 2 arquivos separados
1. package processors;
2. public class ByteProcessor {
3. private static void process(byte[] b) { /* more code here */ }
4. }
1. package apps;
2. public class ByteApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class ByteApp to use the process method of ByteProcessor?
a. process(bytes);
b. ByteProcessor.process(bytes);
c. apps.ByteProcessor.process(bytes);
d. processors.ByteProcessor.process(bytes);
e. import processors.ByteProcessor.*; process(bytes);
f. ByteApp cannot use the process method in ByteProcessor. Correto
Questão
Um desenvolvedor está criand a classe Book, que necessita de acessar a classe Paper. A classe Paper encontra-se em um arquivo JAR
chamado myLib.jar.
Quais 3 dos abaixo que usados independentemente permitirão ao desenvolvedor usar a classe Paper ao compilar a classe Book?
(Escolha três opções.)
a. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar.
b. The JAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar.
c. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar/Paper.class.
d. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar.
e. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac - cp/foo/myLib.jar/Paper Book.java.
f. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d/foo/myLib.jar Book.java
g. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -classpath /foo/myLib.jar Book.java
Questão Resolvida
Um desenvolvedor está criand a classe Book, que necessita de acessar a classe Paper. A classe Paper encontra-se em um arquivo JAR
chamado myLib.jar.
Quais 3 dos abaixo que usados independentemente permitirão ao desenvolvedor usar a classe Paper ao compilar a classe Book?
(Escolha três opções.)
a. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar.
b. The JAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar.
c. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar/Paper.class.
d. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar.
e. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac - cp/foo/myLib.jar/Paper Book.java.
f. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d/foo/myLib.jar Book.java
g. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -classpath /foo/myLib.jar Book.java
Correto
Correto
Correto
Questão
Dado:
1. package com.apps;
2.
3. public class MyApp {
4. public static void main(String[] args) {}
5. }
And MyApp exists in the /programs/com/apps directory. Assume the CLASSPATH environment variable is set to "."
(current directory).
Quais 2 comandos java irão executar MyApp?
(Escolha 2 opções)
A. java MyApp if run from the /programs directory
B. java com.apps.MyApp if run from the /programs directory
C. java -classpath /programs com.apps.MyApp if run from any directory
D. java -classpath . MyApp if run from the /programs/com/apps directory
E. java -classpath /programs/com/apps:. MyApp if run from the /programs directory
F. java com.apps.MyApp if run from the /programs/com/apps directory
Questão Resolvida
Dado:
1. package com.apps;
2.
3. public class MyApp {
4. public static void main(String[] args) {}
5. }
And MyApp exists in the /programs/com/apps directory. Assume the CLASSPATH environment variable is set to "."
(current directory).
Quais 2 comandos java irão executar MyApp?
(Escolha 2 opções)
A. java MyApp if run from the /programs directory
B. java com.apps.MyApp if run from the /programs directory
C. java -classpath /programs com.apps.MyApp if run from any directory
D. java -classpath . MyApp if run from the /programs/com/apps directory
E. java -classpath /programs/com/apps:. MyApp if run from the /programs directory
F. java com.apps.MyApp if run from the /programs/com/apps directory
Correto
Correto
Questão
1. import java.util.*;
2. public class MapTest
3. {
4. public static void main(String[] args)
5. {
6. Object obj = new LinkedHashMap();
7. if(obj instanceof Collection)
8. System.out.print("For ");
9. if(obj instanceof Map)
10. System.out.print("A Few ");
11. if(obj instanceof LinkedList)
12. System.out.print("Dollars More ");
13. if(obj instanceof HashMap)
14. System.out.print("Good Men");
15. }
16. }
O que irá acontecer quando vocÊ tentar compilar e rodar o código acima?
a. It will print - A Few Good Men
b. It will print - For A Few Good Men
c. It will print - For A Few Dollars More Good Men
d. It will print - For A Few Dollars More
e. It will print - For A Few
f. It will print - A Few Dollars More
Questão Resolvida
1. import java.util.*;
2. public class MapTest
3. {
4. public static void main(String[] args)
5. {
6. Object obj = new LinkedHashMap();
7. if(obj instanceof Collection)
8. System.out.print("For ");
9. if(obj instanceof Map)
10. System.out.print("A Few ");
11. if(obj instanceof LinkedList)
12. System.out.print("Dollars More ");
13. if(obj instanceof HashMap)
14. System.out.print("Good Men");
15. }
16. }
O que irá acontecer quando vocÊ tentar compilar e rodar o código acima?
a. It will print - A Few Good Men
b. It will print - For A Few Good Men
c. It will print - For A Few Dollars More Good Men
d. It will print - For A Few Dollars More
e. It will print - For A Few
f. It will print - A Few Dollars More
Correto
Questão
Se o código abaixo exibe: count = 3, qual das declarações abaixo é false? (Assumindo que os métodos equals() e hashCode() foram
sobrescritos corretamente).
1. int count = 1;
2. if(a.equals(b))
3. count++;
4. if(c.equals(d))
5. count++;
6. if(a.hashCode() == b.hashCode())
7. count++;
8. if(c.hashCode() == d.hashCode())
9. count++;
10. System.out.println("count = " + count);
a. a.equals(b) and !(c.equals(d))
b. a.equals(b) or c.equals(d) but not both
c. a.hashCode()==b.hashCode() and c.hashCode() == d.hashCode()
d. a.equals(b) and c.equals(d)
Questão Resolvida
Se o código abaixo exibe: count = 3, qual das declarações abaixo é false? (Assumindo que os métodos equals() e hashCode() foram
sobrescritos corretamente).
1. int count = 1;
2. if(a.equals(b))
3. count++;
4. if(c.equals(d))
5. count++;
6. if(a.hashCode() == b.hashCode())
7. count++;
8. if(c.hashCode() == d.hashCode())
9. count++;
10. System.out.println("count = " + count);
a. a.equals(b) and !(c.equals(d))
b. a.equals(b) or c.equals(d) but not both
c. a.hashCode()==b.hashCode() and c.hashCode() == d.hashCode()
d. a.equals(b) and c.equals(d) Correto
Questão
O que irá acontecer ao tentar compilar e executar o código abaixo?
1. public final class EqualsDemo
2. {
3. private String str;
4.
5. public EqualsDemo(String s)
6. {
7. str = s;
8. }
9.
10. public boolean equals(EqualsDemo obj)
11. {
12. if(!(obj instanceof EqualsDemo))
13. return false;
14. EqualsDemo ed = (EqualsDemo)obj;
15. return (str == ed.str || (str != null && str.equals(ed.str)));
16. }
17.
18. public static void main(String[] args)
19. {
20. EqualsDemo demo1 = new EqualsDemo("Java");
21. EqualsDemo demo2 = new EqualsDemo("java");
22. System.out.println(demo1.equals(demo2));
23. }
24. }
A. It will print - true
B. It will print - false
C. Compilation error
D. Exception
Questão Resolvida
O que irá acontecer ao tentar compilar e executar o código abaixo?
1. public final class EqualsDemo
2. {
3. private String str;
4.
5. public EqualsDemo(String s)
6. {
7. str = s;
8. }
9.
10. public boolean equals(EqualsDemo obj)
11. {
12. if(!(obj instanceof EqualsDemo))
13. return false;
14. EqualsDemo ed = (EqualsDemo)obj;
15. return (str == ed.str || (str != null && str.equals(ed.str)));
16. }
17.
18. public static void main(String[] args)
19. {
20. EqualsDemo demo1 = new EqualsDemo("Java");
21. EqualsDemo demo2 = new EqualsDemo("java");
22. System.out.println(demo1.equals(demo2));
23. }
24. }
A. It will print - true
B. It will print - false
C. Compilation error
D. Exception
Correto
Questão
Como você implementaria do método hashCode() corretamente para a classe abaixo?
(Assumindo que essa classe implemnta o método equals() corretamente e use a implementação mais apropriada)
public class HashDemo
{
private Integer arr[];
//other methods not shown
}
A. public int hashCode()
{
int hash = 7;
if(arr == null)
hash = 31 * hash + 0;
else
for(int i=0; i<arr.length; i++)
{
hash = 31 * hash +(arr[i] == null? 0 : arr[i].hashCode());
}
return hash;
}
B. public int hashCode()
{
int hash = 7;
if(arr == null)
hash = 31 * hash + 0;
else
for(int i=0; i<arr.length; i++)
{
hash = 31 * hash + arr[i].hashCode();
}
return hash;
}
C. public int hashCode()
{
int hash = 7;
if(arr == null)
hash = 31 * hash + 0;
else
hash = 31 * hash + arr.hashCode();
return hash;
}
D. The array should not be involved in the calculation of the
hashCode() method.
Questão Ressolvida
Como você implementaria do método hashCode() corretamente para a classe abaixo?
(Assumindo que essa classe implemnta o método equals() corretamente e use a implementação mais apropriada)
public class HashDemo
{
private Integer arr[];
//other methods not shown
}
A. public int hashCode()
{
int hash = 7;
if(arr == null)
hash = 31 * hash + 0;
else
for(int i=0; i<arr.length; i++)
{
hash = 31 * hash +(arr[i] == null? 0 : arr[i].hashCode());
}
return hash;
}
B. public int hashCode()
{
int hash = 7;
if(arr == null)
hash = 31 * hash + 0;
else
for(int i=0; i<arr.length; i++)
{
hash = 31 * hash + arr[i].hashCode();
}
return hash;
}
C. public int hashCode()
{
int hash = 7;
if(arr == null)
hash = 31 * hash + 0;
else
hash = 31 * hash + arr.hashCode();
return hash;
}
D. The array should not be involved in the calculation of the
hashCode() method.
Correto
Questão
Dado:
2. public class foo {
3. void m1() { }
4. protected void m2 { }
5. }
6. class bar extends foo {
7. // insert code here
8. }
Quais fragmentos de código, inseridos independentemente na linha 7 irão compilar? (Escolha 4)
A. public void m1() { }
B. protected void m1() { }
C. private void m1() { }
D. void m2() { }
E. public void m2() { }
F. protected void m2() { }
G. private void m2() { }
Questão Resolvida
Dado:
2. public class foo {
3. void m1() { }
4. protected void m2 { }
5. }
6. class bar extends foo {
7. // insert code here
8. }
Quais fragmentos de código, inseridos independentemente na linha 7 irão compilar? (Escolha 4)
A. public void m1() { }
B. protected void m1() { }
C. private void m1() { }
D. void m2() { }
E. public void m2() { }
F. protected void m2() { }
G. private void m2() { }
Correto
Correto
Correto
Correto

Mais conteúdo relacionado

Mais procurados

Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Martijn Verburg
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android InfrastructureAlexey Buzdin
 
Python Evolution
Python EvolutionPython Evolution
Python EvolutionQuintagroup
 
Object Oriented Programming - Java
Object Oriented Programming -  JavaObject Oriented Programming -  Java
Object Oriented Programming - JavaDaniel Ilunga
 
Java class 6
Java class 6Java class 6
Java class 6Edureka!
 
Unit2 java
Unit2 javaUnit2 java
Unit2 javamrecedu
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...Guillaume Laforge
 

Mais procurados (9)

Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)Back to the future with Java 7 (Geekout June/2011)
Back to the future with Java 7 (Geekout June/2011)
 
Overview of Android Infrastructure
Overview of Android InfrastructureOverview of Android Infrastructure
Overview of Android Infrastructure
 
Python Evolution
Python EvolutionPython Evolution
Python Evolution
 
Object Oriented Programming - Java
Object Oriented Programming -  JavaObject Oriented Programming -  Java
Object Oriented Programming - Java
 
Java class 6
Java class 6Java class 6
Java class 6
 
EMFPath
EMFPathEMFPath
EMFPath
 
Unit2 java
Unit2 javaUnit2 java
Unit2 java
 
Biopython
BiopythonBiopython
Biopython
 
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
JavaOne 2008 - TS-5793 - Groovy and Grails, changing the landscape of Java EE...
 

Destaque

Day 5 Step 3 - Live It
Day 5   Step 3 - Live ItDay 5   Step 3 - Live It
Day 5 Step 3 - Live Itkirkevan11
 
Day 3 Step 2 - Understand It
Day 3   Step 2 - Understand ItDay 3   Step 2 - Understand It
Day 3 Step 2 - Understand Itkirkevan11
 
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 Wordkirkevan11
 

Destaque (6)

Inspiratieboek incassoplein
Inspiratieboek incassopleinInspiratieboek incassoplein
Inspiratieboek incassoplein
 
Day 5 Step 3 - Live It
Day 5   Step 3 - Live ItDay 5   Step 3 - Live It
Day 5 Step 3 - Live It
 
Day 3 Step 2 - Understand It
Day 3   Step 2 - Understand ItDay 3   Step 2 - Understand It
Day 3 Step 2 - Understand It
 
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
 
Tabela da liga, mata mata
Tabela da liga, mata mataTabela da liga, mata mata
Tabela da liga, mata mata
 
Tabela da liga, mata mata
Tabela da liga, mata mataTabela da liga, mata mata
Tabela da liga, mata mata
 

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

Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satyaSatya Johnny
 
How to run java program without IDE
How to run java program without IDEHow to run java program without IDE
How to run java program without IDEShweta Oza
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAVINASH KUMAR
 
Class loader basic
Class loader basicClass loader basic
Class loader basic명철 강
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpathAlexis Hassler
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)Prof. Erwin Globio
 
java basic for begginers
java basic for begginersjava basic for begginers
java basic for begginersdivaskrgupta007
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdfvenud11
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz SAurabh PRajapati
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnitGreg.Helton
 
Moving to Module: Issues & Solutions
Moving to Module: Issues & SolutionsMoving to Module: Issues & Solutions
Moving to Module: Issues & SolutionsYuichi Sakuraba
 
Java class 3
Java class 3Java class 3
Java class 3Edureka!
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy PluginsPaul King
 
Create & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxCreate & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxvishal choudhary
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsRasan Samarasinghe
 
Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationJames Hamilton
 

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

Adv kvr -satya
Adv  kvr -satyaAdv  kvr -satya
Adv kvr -satya
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
 
How to run java program without IDE
How to run java program without IDEHow to run java program without IDE
How to run java program without IDE
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
 
Class loader basic
Class loader basicClass loader basic
Class loader basic
 
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw  est prêt à tuer le classpathSoft-Shake 2016 : Jigsaw  est prêt à tuer le classpath
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
Java Quiz - Meetup
Java Quiz - MeetupJava Quiz - Meetup
Java Quiz - Meetup
 
Java For Automation
Java   For AutomationJava   For Automation
Java For Automation
 
java basic for begginers
java basic for begginersjava basic for begginers
java basic for begginers
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
 
Inheritance
InheritanceInheritance
Inheritance
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
 
Moving to Module: Issues & Solutions
Moving to Module: Issues & SolutionsMoving to Module: Issues & Solutions
Moving to Module: Issues & Solutions
 
Java class 3
Java class 3Java class 3
Java class 3
 
Atlassian Groovy Plugins
Atlassian Groovy PluginsAtlassian Groovy Plugins
Atlassian Groovy Plugins
 
Create & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptxCreate & Execute First Hadoop MapReduce Project in.pptx
Create & Execute First Hadoop MapReduce Project in.pptx
 
Esoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basicsEsoft Metro Campus - Certificate in java basics
Esoft Metro Campus - Certificate in java basics
 
Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 Presentation
 

Mais de Julio Cesar Nunes de Souza

Mais de Julio Cesar Nunes de Souza (8)

Introdução AngularJS 4 com CLI
Introdução AngularJS 4 com CLIIntrodução AngularJS 4 com CLI
Introdução AngularJS 4 com CLI
 
Visão geral sobre Assertivas e Exceções no Java7
Visão geral sobre Assertivas e Exceções no Java7Visão geral sobre Assertivas e Exceções no Java7
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...
 "Mas eu não tenho experiência..." E daí??? - Como quebrar o ciclo vicioso de... "Mas eu não tenho experiência..." E daí??? - Como quebrar o ciclo vicioso de...
"Mas eu não tenho experiência..." E daí??? - Como quebrar o ciclo vicioso de...
 
Revisao OCPJP - Princípios OO
Revisao OCPJP - Princípios OORevisao OCPJP - Princípios OO
Revisao OCPJP - Princípios OO
 
Revisão OCPJP7 - String Processing
Revisão OCPJP7 - String ProcessingRevisão OCPJP7 - String Processing
Revisão OCPJP7 - String Processing
 
Revisão OCPJP7 - Class Design (parte 04)
Revisão OCPJP7 - Class Design (parte 04)Revisão OCPJP7 - Class Design (parte 04)
Revisão OCPJP7 - Class Design (parte 04)
 
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 03)
Revisão OCPJP7 - Class Design (parte 03)Revisão OCPJP7 - Class Design (parte 03)
Revisão OCPJP7 - Class Design (parte 03)
 

Último

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Último (20)

ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Revisão OCPJP7 - Class Design (parte 01)

  • 2. Questão Dado: package com.sun.scjp; public class Geometry { public static final double DIAMETER = 0.72; // kilometers } Quais 2 podem acessar o membro DIAMETER corretamente da classe Geometry? (Escola 2 opções) A. import com.sun.scjp.Geometry; public class Ground { public double halfway { return Geometry.DIAMETER/2.0; } } B. import static com.sun.scjp.Geometry; public class Ground { public double halfway { return DIAMETER/2.0; } } C. import static com.sun.scjp.Geometry.*; public class Ground { public double halfway { return DIAMETER/2.0; } } D. package com.sun.scjp; public class Ground { public double halfway { return DIAMETER/2.0; } }
  • 3. Questão Resolvida Dado: package com.sun.scjp; public class Geometry { public static final double DIAMETER = 0.72; // kilometers } Quais 2 podem acessar o membro DIAMETER corretamente da classe Geometry? (Escola 2 opções) A. import com.sun.scjp.Geometry; public class Ground { public double halfway { return Geometry.DIAMETER/2.0; } } B. import static com.sun.scjp.Geometry; public class Ground { public double halfway { return DIAMETER/2.0; } } C. import static com.sun.scjp.Geometry.*; public class Ground { public double halfway { return DIAMETER/2.0; } } D. package com.sun.scjp; public class Ground { public double halfway { return DIAMETER/2.0; } } Correto Correto
  • 4. Questão As classes abaixo estão definidas em 2 arquivos separados 1. package processors; 2. public class ByteProcessor { 3. public static void process(byte[] b) { /* more code here */ } 4. } 1. package apps; 2. public class ByteApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } O que é necessário na linha 5 da classe ByteApp para usar o método da classe ByteProcessor? a. process(bytes); b. ByteProcessor.process(bytes); c. processors.ByteProcessor.process(bytes); d. ByteApp cannot use methods in ByteProcessor. e. import processors.ByteProcessors.*; process(bytes);
  • 5. Questão Resolvida As classes abaixo estão definidas em 2 arquivos separados 1. package processors; 2. public class ByteProcessor { 3. public static void process(byte[] b) { /* more code here */ } 4. } 1. package apps; 2. public class ByteApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } O que é necessário na linha 5 da classe ByteApp para usar o método da classe ByteProcessor? a. process(bytes); b. ByteProcessor.process(bytes); c. processors.ByteProcessor.process(bytes); d. ByteApp cannot use methods in ByteProcessor. e. import processors.ByteProcessors.*; process(bytes); Correto
  • 6. Questão As classes abaixo estão definidas em 2 arquivos separados 1. package processors; 2. public class ByteProcessor { 3. private static void process(byte[] b) { /* more code here */ } 4. } 1. package apps; 2. public class ByteApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class ByteApp to use the process method of ByteProcessor? a. process(bytes); b. ByteProcessor.process(bytes); c. apps.ByteProcessor.process(bytes); d. processors.ByteProcessor.process(bytes); e. import processors.ByteProcessor.*; process(bytes); f. ByteApp cannot use the process method in ByteProcessor.
  • 7. Questão Resolvida As classes abaixo estão definidas em 2 arquivos separados 1. package processors; 2. public class ByteProcessor { 3. private static void process(byte[] b) { /* more code here */ } 4. } 1. package apps; 2. public class ByteApp { 3. public static void main(String[] args) { 4. byte[] bytes = new byte[256]; 5. // insert code here 6. } 7. } What is required at line 5 in class ByteApp to use the process method of ByteProcessor? a. process(bytes); b. ByteProcessor.process(bytes); c. apps.ByteProcessor.process(bytes); d. processors.ByteProcessor.process(bytes); e. import processors.ByteProcessor.*; process(bytes); f. ByteApp cannot use the process method in ByteProcessor. Correto
  • 8. Questão Um desenvolvedor está criand a classe Book, que necessita de acessar a classe Paper. A classe Paper encontra-se em um arquivo JAR chamado myLib.jar. Quais 3 dos abaixo que usados independentemente permitirão ao desenvolvedor usar a classe Paper ao compilar a classe Book? (Escolha três opções.) a. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar. b. The JAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar. c. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar/Paper.class. d. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar. e. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac - cp/foo/myLib.jar/Paper Book.java. f. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d/foo/myLib.jar Book.java g. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -classpath /foo/myLib.jar Book.java
  • 9. Questão Resolvida Um desenvolvedor está criand a classe Book, que necessita de acessar a classe Paper. A classe Paper encontra-se em um arquivo JAR chamado myLib.jar. Quais 3 dos abaixo que usados independentemente permitirão ao desenvolvedor usar a classe Paper ao compilar a classe Book? (Escolha três opções.) a. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar. b. The JAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar. c. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar/Paper.class. d. The JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar. e. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac - cp/foo/myLib.jar/Paper Book.java. f. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d/foo/myLib.jar Book.java g. The JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -classpath /foo/myLib.jar Book.java Correto Correto Correto
  • 10. Questão Dado: 1. package com.apps; 2. 3. public class MyApp { 4. public static void main(String[] args) {} 5. } And MyApp exists in the /programs/com/apps directory. Assume the CLASSPATH environment variable is set to "." (current directory). Quais 2 comandos java irão executar MyApp? (Escolha 2 opções) A. java MyApp if run from the /programs directory B. java com.apps.MyApp if run from the /programs directory C. java -classpath /programs com.apps.MyApp if run from any directory D. java -classpath . MyApp if run from the /programs/com/apps directory E. java -classpath /programs/com/apps:. MyApp if run from the /programs directory F. java com.apps.MyApp if run from the /programs/com/apps directory
  • 11. Questão Resolvida Dado: 1. package com.apps; 2. 3. public class MyApp { 4. public static void main(String[] args) {} 5. } And MyApp exists in the /programs/com/apps directory. Assume the CLASSPATH environment variable is set to "." (current directory). Quais 2 comandos java irão executar MyApp? (Escolha 2 opções) A. java MyApp if run from the /programs directory B. java com.apps.MyApp if run from the /programs directory C. java -classpath /programs com.apps.MyApp if run from any directory D. java -classpath . MyApp if run from the /programs/com/apps directory E. java -classpath /programs/com/apps:. MyApp if run from the /programs directory F. java com.apps.MyApp if run from the /programs/com/apps directory Correto Correto
  • 12. Questão 1. import java.util.*; 2. public class MapTest 3. { 4. public static void main(String[] args) 5. { 6. Object obj = new LinkedHashMap(); 7. if(obj instanceof Collection) 8. System.out.print("For "); 9. if(obj instanceof Map) 10. System.out.print("A Few "); 11. if(obj instanceof LinkedList) 12. System.out.print("Dollars More "); 13. if(obj instanceof HashMap) 14. System.out.print("Good Men"); 15. } 16. } O que irá acontecer quando vocÊ tentar compilar e rodar o código acima? a. It will print - A Few Good Men b. It will print - For A Few Good Men c. It will print - For A Few Dollars More Good Men d. It will print - For A Few Dollars More e. It will print - For A Few f. It will print - A Few Dollars More
  • 13. Questão Resolvida 1. import java.util.*; 2. public class MapTest 3. { 4. public static void main(String[] args) 5. { 6. Object obj = new LinkedHashMap(); 7. if(obj instanceof Collection) 8. System.out.print("For "); 9. if(obj instanceof Map) 10. System.out.print("A Few "); 11. if(obj instanceof LinkedList) 12. System.out.print("Dollars More "); 13. if(obj instanceof HashMap) 14. System.out.print("Good Men"); 15. } 16. } O que irá acontecer quando vocÊ tentar compilar e rodar o código acima? a. It will print - A Few Good Men b. It will print - For A Few Good Men c. It will print - For A Few Dollars More Good Men d. It will print - For A Few Dollars More e. It will print - For A Few f. It will print - A Few Dollars More Correto
  • 14. Questão Se o código abaixo exibe: count = 3, qual das declarações abaixo é false? (Assumindo que os métodos equals() e hashCode() foram sobrescritos corretamente). 1. int count = 1; 2. if(a.equals(b)) 3. count++; 4. if(c.equals(d)) 5. count++; 6. if(a.hashCode() == b.hashCode()) 7. count++; 8. if(c.hashCode() == d.hashCode()) 9. count++; 10. System.out.println("count = " + count); a. a.equals(b) and !(c.equals(d)) b. a.equals(b) or c.equals(d) but not both c. a.hashCode()==b.hashCode() and c.hashCode() == d.hashCode() d. a.equals(b) and c.equals(d)
  • 15. Questão Resolvida Se o código abaixo exibe: count = 3, qual das declarações abaixo é false? (Assumindo que os métodos equals() e hashCode() foram sobrescritos corretamente). 1. int count = 1; 2. if(a.equals(b)) 3. count++; 4. if(c.equals(d)) 5. count++; 6. if(a.hashCode() == b.hashCode()) 7. count++; 8. if(c.hashCode() == d.hashCode()) 9. count++; 10. System.out.println("count = " + count); a. a.equals(b) and !(c.equals(d)) b. a.equals(b) or c.equals(d) but not both c. a.hashCode()==b.hashCode() and c.hashCode() == d.hashCode() d. a.equals(b) and c.equals(d) Correto
  • 16. Questão O que irá acontecer ao tentar compilar e executar o código abaixo? 1. public final class EqualsDemo 2. { 3. private String str; 4. 5. public EqualsDemo(String s) 6. { 7. str = s; 8. } 9. 10. public boolean equals(EqualsDemo obj) 11. { 12. if(!(obj instanceof EqualsDemo)) 13. return false; 14. EqualsDemo ed = (EqualsDemo)obj; 15. return (str == ed.str || (str != null && str.equals(ed.str))); 16. } 17. 18. public static void main(String[] args) 19. { 20. EqualsDemo demo1 = new EqualsDemo("Java"); 21. EqualsDemo demo2 = new EqualsDemo("java"); 22. System.out.println(demo1.equals(demo2)); 23. } 24. } A. It will print - true B. It will print - false C. Compilation error D. Exception
  • 17. Questão Resolvida O que irá acontecer ao tentar compilar e executar o código abaixo? 1. public final class EqualsDemo 2. { 3. private String str; 4. 5. public EqualsDemo(String s) 6. { 7. str = s; 8. } 9. 10. public boolean equals(EqualsDemo obj) 11. { 12. if(!(obj instanceof EqualsDemo)) 13. return false; 14. EqualsDemo ed = (EqualsDemo)obj; 15. return (str == ed.str || (str != null && str.equals(ed.str))); 16. } 17. 18. public static void main(String[] args) 19. { 20. EqualsDemo demo1 = new EqualsDemo("Java"); 21. EqualsDemo demo2 = new EqualsDemo("java"); 22. System.out.println(demo1.equals(demo2)); 23. } 24. } A. It will print - true B. It will print - false C. Compilation error D. Exception Correto
  • 18. Questão Como você implementaria do método hashCode() corretamente para a classe abaixo? (Assumindo que essa classe implemnta o método equals() corretamente e use a implementação mais apropriada) public class HashDemo { private Integer arr[]; //other methods not shown } A. public int hashCode() { int hash = 7; if(arr == null) hash = 31 * hash + 0; else for(int i=0; i<arr.length; i++) { hash = 31 * hash +(arr[i] == null? 0 : arr[i].hashCode()); } return hash; } B. public int hashCode() { int hash = 7; if(arr == null) hash = 31 * hash + 0; else for(int i=0; i<arr.length; i++) { hash = 31 * hash + arr[i].hashCode(); } return hash; } C. public int hashCode() { int hash = 7; if(arr == null) hash = 31 * hash + 0; else hash = 31 * hash + arr.hashCode(); return hash; } D. The array should not be involved in the calculation of the hashCode() method.
  • 19. Questão Ressolvida Como você implementaria do método hashCode() corretamente para a classe abaixo? (Assumindo que essa classe implemnta o método equals() corretamente e use a implementação mais apropriada) public class HashDemo { private Integer arr[]; //other methods not shown } A. public int hashCode() { int hash = 7; if(arr == null) hash = 31 * hash + 0; else for(int i=0; i<arr.length; i++) { hash = 31 * hash +(arr[i] == null? 0 : arr[i].hashCode()); } return hash; } B. public int hashCode() { int hash = 7; if(arr == null) hash = 31 * hash + 0; else for(int i=0; i<arr.length; i++) { hash = 31 * hash + arr[i].hashCode(); } return hash; } C. public int hashCode() { int hash = 7; if(arr == null) hash = 31 * hash + 0; else hash = 31 * hash + arr.hashCode(); return hash; } D. The array should not be involved in the calculation of the hashCode() method. Correto
  • 20. Questão Dado: 2. public class foo { 3. void m1() { } 4. protected void m2 { } 5. } 6. class bar extends foo { 7. // insert code here 8. } Quais fragmentos de código, inseridos independentemente na linha 7 irão compilar? (Escolha 4) A. public void m1() { } B. protected void m1() { } C. private void m1() { } D. void m2() { } E. public void m2() { } F. protected void m2() { } G. private void m2() { }
  • 21. Questão Resolvida Dado: 2. public class foo { 3. void m1() { } 4. protected void m2 { } 5. } 6. class bar extends foo { 7. // insert code here 8. } Quais fragmentos de código, inseridos independentemente na linha 7 irão compilar? (Escolha 4) A. public void m1() { } B. protected void m1() { } C. private void m1() { } D. void m2() { } E. public void m2() { } F. protected void m2() { } G. private void m2() { } Correto Correto Correto Correto