Quiz
Chapter 3 Core Java APIs
Crie uma conta grátis para terminar este quiz
Salve seu progresso e veja sua nota final.
Já tem uma conta? Inicie sessão
Perguntas do quiz (33)
1What is output by the following code? (Choose all that apply).
1: public class Fish {
2: public static void main(String[] args) {
3: int numFish = 4;
4: String fishType = "tuna";
5: String anotherFish = numFish + 1;
6: System.out.println(anotherFish + " " + fishType);
7: System.out.println(numFish + " " + 1);
8: } }- A4 1
- B41
- C5
- D5 tuna
- E5tuna
- F51tuna
- GThe code does not compile.
2Which of the following are output by this code? (Choose all that apply)
3: String s = "Hello";
4: String t = new String(s);
5: if ("Hello".equals(s)) System.out.println("one");
6: if (t == s) System.out.println("two");
7: if (t.equals(s)) System.out.println("three");
8: if ("Hello" == s) System.out.println("four");
9: if ("Hello" == t) System.out.println("five");- Aone
- Btwo
- Cthree
- Dfour
- Efive
- FThe code does not compile.
3Which are true statements? (Choose all that apply)
- AAn immutable object can be modified.
- BAn immutable object cannot be modified.
- CAn immutable object can be garbage collected.
- DAn immutable object cannot be garbage collected.
- EString is immutable.
- FStringBuffer is immutable.
- GStringBuilder is immutable.
4What is the result of the following code?
7: StringBuilder sb = new StringBuilder();
8: sb.append("aaa").insert(1, "bb").insert(4, "ccc");
9: System.out.println(sb);- Aabbaaccc
- Babbaccca
- Cbbaaaccc
- Dbbaaccca
- EAn exception is thrown.
- FThe code does not compile.
5What is the result of the following code?
2: String s1 = "java";
3: StringBuilder s2 = new StringBuilder("java");
4: if (s1 == s2)
5: System.out.print("1");
6: if (s1.equals(s2))
7: System.out.print("2");- A1
- B2
- C12
- DNo output is printed.
- EAn exception is thrown.
- FThe code does not compile.
6What is the result of the following code?
public class Lion {
public void roar(String roar1, StringBuilder roar2) {
roar1.concat("!!!");
roar2.append("!!!");
}
public static void main(String[] args) {
String roar1 = "roar";
StringBuilder roar2 = new StringBuilder("roar");
new Lion().roar(roar1, roar2);
System.out.println(roar1 + " " + roar2);
} }- Aroar roar
- Broar roar!!!
- Croar!!! roar
- Droar!!! roar!!!
- EAn exception is thrown.
- FThe code does not compile.
7Which are the results of the following code? (Choose all that apply)
String letters = "abcdef";
System.out.println(letters.length());
System.out.println(letters.charAt(3));
System.out.println(letters.charAt(6));- A5
- B6
- Cc
- Dd
- EAn exception is thrown.
- FThe code does not compile.
8Which are the results of the following code? (Choose all that apply)
String numbers = "012345678";
System.out.println(numbers.substring(1, 3));
System.out.println(numbers.substring(7, 7));
System.out.println(numbers.substring(7));- A12
- B123
- C7
- D78
- EA blank line.
- FAn exception is thrown.
- GThe code does not compile.
9What is the result of the following code?
3: String s = "purr";
4: s.toUpperCase();
5: s.trim();
6: s.substring(1, 3);
7: s += " two";
8: System.out.println(s.length());- A2
- B4
- C8
- D10
- EAn exception is thrown.
- FThe code does not compile.
10What is the result of the following code? (Choose all that apply)
13: String a = "";
14: a += 2;
15: a += 'c';
16: a += false;
17: if ( a == "2cfalse") System.out.println("==");
18: if ( a.equals("2cfalse")) System.out.println("equals");- ACompile error on line 14.
- BCompile error on line 15.
- CCompile error on line 16.
- DCompile error on another line.
- E==
- Fequals
- GAn exception is thrown.
11What is the result of the following code?
4: int total = 0;
5: StringBuilder letters = new StringBuilder("abcdefg");
6: total += letters.substring(1, 2).length();
7: total += letters.substring(6, 6).length();
8: total += letters.substring(6, 5).length();
9: System.out.println(total);- A1
- B2
- C3
- D7
- EAn exception is thrown.
- FThe code does not compile.
12What is the result of the following code? (Choose all that apply)
StringBuilder numbers = new StringBuilder("0123456789");
numbers.delete(2, 8);
numbers.append("-").insert(2, "+");
System.out.println(numbers);- A01+89–
- B012+9–
- C012+–9
- D0123456789
- EAn exception is thrown.
- FThe code does not compile.
13What is the result of the following code?
StringBuilder b = "rumble";
b.append(4).deleteCharAt(3).delete(3, b.length() - 1);
System.out.println(b);- Arum
- Brum4
- Crumb4
- Drumble4
- EAn exception is thrown.
- FThe code does not compile.
14Which of the following can replace line 4 to print "avaJ"? (Choose all that apply)
3: StringBuilder puzzle = new StringBuilder("Java");
4: // INSERT CODE HERE
5: System.out.println(puzzle);- Apuzzle.reverse();
- Bpuzzle.append("vaJ$").substring(0, 4);
- Cpuzzle.append("vaJ$").delete(0, 3).deleteCharAt(puzzle.length() - 1);
- Dpuzzle.append("vaJ$").delete(0, 3).deleteCharAt(puzzle.length());
- ENone of the above.
15Which of these array declarations is not legal? (Choose all that apply)
- Aint[][] scores = new int[5][];
- BObject[][][] cubbies = new Object[3][0][5];
- CString beans[] = new beans[6];
- Djava.util.Date[] dates[] = new java.util.Date[2][];
- Eint[][] types = new int[];
- Fint[][] java = new int[][];
16Which of these compile when replacing line 8? (Choose all that apply)
7: char[]c = new char[2];
8: // INSERT CODE HERE- Aint length = c.capacity;
- Bint length = c.capacity();
- Cint length = c.length;
- Dint length = c.length();
- Eint length = c.size;
- Fint length = c.size();
- GNone of the above.
17Which of these compile when replacing line 8? (Choose all that apply)
7: ArrayList l = new ArrayList();
8: // INSERT CODE HERE- Aint length = l.capacity;
- Bint length = l.capacity();
- Cint length = l.length;
- Dint length = l.length();
- Eint length = l.size;
- Fint length = l.size();
- GNone of the above.
18Which of the following are true? (Choose all that apply)
- AAn array has a fixed size.
- BAn ArrayList has a fixed size.
- CAn array allows multiple dimensions.
- DAn array is ordered.
- EAn ArrayList is ordered.
- FAn array is immutable.
- GAn ArrayList is immutable.
19Which of the following are true? (Choose all that apply)
- ATwo arrays with the same content are equal.
- BTwo ArrayLists with the same content are equal.
- CIf you call remove(0) using an empty ArrayList object, it will compile successfully.
- DIf you call remove(0) using an empty ArrayList object, it will run successfully.
- ENone of the above.
20What is the result of the following statements?
6: List<String> list = new ArrayList<String>();
7: list.add("one");
8: list.add("two");
9: list.add(7);
10: for(String s : list) System.out.print(s);- Aonetwo
- Bonetwo7
- Conetwo followed by an exception
- DCompiler error on line 9.
- ECompiler error on line 10.
21What is the result of the following statements?
3: ArrayList<Integer> values = new ArrayList<>();
4: values.add(4);
5: values.add(5);
6: values.set(1, 6);
7: values.remove(0);
8: for (Integer v : values) System.out.print(v);- A4
- B5
- C6
- D46
- E45
- FAn exception is thrown.
- GThe code does not compile.
22What is the result of the following?
int[] random = { 6, -4, 12, 0, -10 };
int x = 12;
int y = Arrays.binarySearch(random, x);
System.out.println(y);- A2
- B4
- C6
- DThe result is undefined.
- EAn exception is thrown.
- FThe code does not compile.
23What is the result of the following?
4: List<Integer> list = Arrays.asList(10, 4, -1, 5);
5: Collections.sort(list);
6: Integer array[] = list.toArray(new Integer[4]);
7: System.out.println(array[0]);- A-1
- B10
- CCompiler error on line 4.
- DCompiler error on line 5.
- ECompiler error on line 6.
- FAn exception is thrown.
24What is the result of the following?
6: String [] names = {"Tom", "Dick", "Harry"};
7: List<String> list = names.asList();
8: list.set(0, "Sue");
9: System.out.println(names[0]);- Asue
- BTom
- CCompiler error on line 7.
- DCompiler error on line 8.
- EAn exception is thrown.
25What is the result of the following?
List<String> hex = Arrays.asList("30", "8", "3A", "FF");
Collections.sort(hex);
int x = Collections.binarySearch(hex, "8");
int y = Collections.binarySearch(hex, "3A");
int z = Collections.binarySearch(hex, "4F");
System.out.println(x + " " + y + " " + z);- A0 1 –2
- B0 1 –3
- C2 1 –2
- D2 1 –3
- ENone of the above.
- FThe code doesn’t compile.
26Which of the following are true statements about the following code? (Choose all that
apply)
4: List<Integer> ages = new ArrayList<>();
5: ages.add(Integer.parseInt("5"));
6: ages.add(Integer.valueOf("6"));
7: ages.add(7);
8: ages.add(null);
9: for (int age : ages) System.out.print(age);- AThe code compiles.
- BThe code throws a runtime exception.
- CExactly one of the add statements uses autoboxing.
- DExactly two of the add statements use autoboxing.
- EExactly three of the add statements use autoboxing.
27What is the result of the following?
List<String> one = new ArrayList<String>();
one.add("abc");
List<String> two = new ArrayList<>();
two.add("abc");
if (one == two)
System.out.println("A");
else if (one.equals(two))
System.out.println("B");
else
System.out.println("C");- AA
- BB
- CC
- DAn exception is thrown.
- EThe code does not compile.
28Which of the following can be inserted into the blank to create a date of June 21, 2014?
(Choose all that apply)
import java.time.*;
public class StartOfSummer {
public static void main(String[] args) {
LocalDate date = ____________________________
}
}- Anew LocalDate(2014, 5, 21);
- Bnew LocalDate(2014, 6, 21);
- CLocalDate.of(2014, 5, 21);
- DLocalDate.of(2014, 6, 21);
- ELocalDate.of(2014, Calendar.JUNE, 21);
- FLocalDate.of(2014, Month.JUNE, 21);
29What is the output of the following code?
LocalDate date = LocalDate.parse("2018-04-30", DateTimeFormatter.ISO_LOCAL_DATE);
date.plusDays(2);
date.plusHours(3);
System.out.println(date.getYear() + " " + date.getMonth() + " "+ date.getDayOfMonth());- A2018 APRIL 2
- B2018 APRIL 30
- C2018 MAY 2
- DThe code does not compile.
- EA runtime exception is thrown.
30What is the output of the following code?
LocalDate date = LocalDate.of(2018, Month.APRIL, 40);
System.out.println(date.getYear() + " " + date.getMonth() + " "
+ date.getDayOfMonth());- A2018 APRIL 4
- B2018 APRIL 30
- C2018 MAY 10
- DAnother date.
- EThe code does not compile.
- FA runtime exception is thrown.
31What is the output of the following code?
LocalDate date = LocalDate.of(2018, Month.APRIL, 30);
date.plusDays(2);
date.plusYears(3);
System.out.println(date.getYear() + " " + date.getMonth() + " "
+ date.getDayOfMonth());- A2018 APRIL 2
- B2018 APRIL 30
- C2018 MAY 2
- D2021 APRIL 2
- E2021 APRIL 30
- F2021 MAY 2
- GA runtime exception is thrown.
32What is the output of the following code?
LocalDateTime d = LocalDateTime.of(2015, 5, 10, 11, 22, 33);
Period p = Period.of(1, 2, 3);
d = d.minus(p);
DateTimeFormatter f = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
System.out.println(d.format(f));- A3/7/14 11:22 AM
- B5/10/15 11:22 AM
- C3/7/14
- D5/10/15
- E11:22 AM
- FThe code does not compile.
- GA runtime exception is thrown.
33What is the output of the following code?
LocalDateTime d = LocalDateTime.of(2015, 5, 10, 11, 22, 33);
Period p = Period.ofDays(1).ofYears(2);
d = d.minus(p);
DateTimeFormatter f = DateTimeFormatter.ofLocalizedDateTime(FormatStyle
.SHORT);
System.out.println(f.format(d));- A5/9/13 11:22 AM
- B5/10/13 11:22 AM
- C5/9/14
- D5/10/14
- EThe code does not compile.
- FA runtime exception is thrown.
Informações
- Descrição
- OCA JAVA 8 (OCA) Quiz sobre Chapter 3 Core Java APIs, criado por Fausto Trindade em 26-05-2020.
- Autor
- Fausto Trindade
- Idioma
- Português
- Visualizações
- 12
- Etiquetas
- Avaliação
- Ainda sem avaliações Avalie este quiz