SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt? (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...
 

Andere mochten auch

Andere mochten auch (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
 

Ähnlich wie Revisão OCPJP7 - Class Design (parte 01)

Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
Satya Johnny
 
Class loader basic
Class loader basicClass loader basic
Class loader basic
명철 강
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
venud11
 
Unit Testing RPG with JUnit
Unit Testing RPG with JUnitUnit Testing RPG with JUnit
Unit Testing RPG with JUnit
Greg.Helton
 
Java class 3
Java class 3Java class 3
Java class 3
Edureka!
 

Ähnlich wie 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
 

Mehr von 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)
 

Kürzlich hochgeladen

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 

Kürzlich hochgeladen (20)

Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 

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