[2024年06月07日] 最速準備で試験合格!1z1-829問題の事前予備
1z1-829のPDF問題集リアル2024最近更新された問題
質問 # 21
Given:
What is the result?
- A. Software Game Software Game Chese 2
- B. Software Game read error
- C. Software game write error
- D. Software Game Chess 2
- E. Software Game Chess 0
- F. Software Game Software Game chess 0
正解:A
解説:
The answer is B because the code uses the writeObject and readObject methods of the ObjectOutputStream and ObjectInputStream classes to serialize and deserialize the Game object. These methods use the default serialization mechanism, which writes and reads the state of the object's fields, including the inherited ones. Therefore, the title field of the Software class is also serialized and deserialized along with the players field of the Game class. The toString method of the Game class calls the toString method of the Software class using super.toString(), which returns the value of the title field. Hence, when the deserialized object is printed, it shows "Software Game Software Game Chess 2". Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Serialization and Deserialization in Java with Example
質問 # 22
Given:
- A. there
- B. A NumberFormatException is thrown
- C. Compilation fails
- D. Hello
正解:C
解説:
The code fragment will fail to compile because the parseInt method of the Integer class is a static method, which means that it can be invoked without creating an object of the class. However, the code is trying to invoke the parseInt method on an object of type Integer, which is not allowed. The correct way to invoke the parseInt method is by using the class name, such as Integer.parseInt (s). Therefore, the code fragment will produce a compilation error. Reference: Integer (Java SE 17 & JDK 17) - Oracle
質問 # 23
Given the code fragment:
What is the result?
- A. True true false NewYear
- B. 0110
- C. False true true optional (Newyear)
- D. 010 optional (Newyear)
正解:C
解説:
Explanation
The code fragment is using the stream methods allMatch, anyMatch, noneMatch, and findFirst on a list of strings called specialDays. These methods are used to perform matching operations on the elements of a stream, such as checking if all, any, or none of the elements satisfy a given predicate, or finding the first element that matches a predicate1. The predicate in this case is that the string equals "Labour" or
"Halloween". The output will be:
False: because not all of the elements in specialDays are equal to "Labour" or "Halloween".
true: because at least one of the elements in specialDays is equal to "Labour" or "Halloween".
true: because none of the elements in specialDays are equal to both "Labour" and "Halloween".
Optional[NewYear]: because the first element in specialDays that matches the predicate is "NewYear", and the findFirst method returns an Optional object that may or may not contain a non-null value2.
References: Stream (Java SE 17 & JDK 17), Optional (Java SE 17 & JDK 17)
質問 # 24
Given:
What is the result?
- A. Bicycle =7, car=7, motorcycle=7, truck=7)
- B. (3:bicycle, 0:car, 0motercycle, 5:truck)
- C. Compilation fails.
- D. Bicycle-1, car=3, motorcycle=1, truck=2)
- E. (Bicycle, car, motorcycle, truck)
正解:C
解説:
Explanation
The answer is E because the code fragment contains several syntax errors that prevent it from compiling.
Some of the errors are:
The enum declaration is missing a semicolon after the list of constants.
The enum constants are not capitalized, which violates the Java naming convention for enums.
The switch expression is missing parentheses around the variable name.
The case labels are missing colons after the enum constants.
The default label is missing a break statement, which causes a fall-through to the next case.
The println statement is missing a closing parenthesis and a semicolon.
A possible corrected version of the code fragment is:
enum Vehicle { BICYCLE, CAR, MOTORCYCLE, TRUCK; } public class Test { public static void main(String[] args) { Vehicle v = Vehicle.BICYCLE; switch (v) { case BICYCLE: System.out.print("1"); break; case CAR: System.out.print("3"); break; case MOTORCYCLE: System.out.print("1"); break; case TRUCK: System.out.print("2"); break; default: System.out.print("0"); break; } System.out.println(); } } This would print 1 as the output. References:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Enum Types
The switch Statement
質問 # 25
Given the code fragments:
Which action prints Wagon : 200?
- A. At Line n1, implement the java.io.AutoCloseable interface
- B. At Line n3, replace Car with LuxurayCar.
- C. At line n3, replace readObject (0 with readLine().
- D. At line n1, implement the java.io, Serializable interface.
- E. At line n2, in the main method signature, add throws IOException, ClassCastException.
- F. At line n2, in the main method signature, add throws IoException, ClassNotFoundException.
正解:F
解説:
The code fragment is trying to read an object from a file using the ObjectInputStream class. This class throws an IOException and a ClassNotFoundException. To handle these exceptions, the main method signature should declare that it throws these exceptions. Otherwise, the code will not compile. If the main method throws these exceptions, the code will print Wagon : 200, which is the result of calling the toString method of the LuxuryCar object that was written to the file. Reference: ObjectInputStream (Java SE 17 & JDK 17) - Oracle, ObjectOutputStream (Java SE 17 & JDK 17) - Oracle
質問 # 26
Given:
What is the result?
- A. 1 Snowy
- B. 0 Snowy
- C. Compilation fails
- D. 1 RAINY
- E. 0 CLOUDY
正解:B
解説:
Explanation
The code is defining an enum class called Forecast with three values: SUNNY, CLOUDY, and RAINY. The toString() method is overridden to always return "SNOWY". In the main method, the ordinal value of SUNNY is printed, which is 0, followed by the value of CLOUDY converted to uppercase, which is "CLOUDY".
However, since the toString() method of Forecast returns "SNOWY" regardless of the actual value, the output will be "0 SNOWY". References: Enum (Java SE 17 & JDK 17), Enum.EnumDesc (Java SE 17 & JDK 17)
質問 # 27
Which statement is true?
- A. IllegalStateException is thrown if a thread in waiting state is moved back to runnable.
- B. thread in waiting state consumes CPU cycles.
- C. A thread in waiting state must handle InterrupedException.
- D. After the timed wait expires, the waited thread moves to the terminated state.
正解:C
解説:
A thread in waiting state is waiting for another thread to perform a particular action, such as calling notify() or notifyAll() on a shared object, or terminating a joined thread. A thread in waiting state can be interrupted by another thread, which will cause the waiting thread to throw an InterruptedException and return to the runnable state. Therefore, a thread in waiting state must handle InterruptedException, either by catching it or declaring it in the throws clause. Reference: Thread.State (Java SE 17 & JDK 17), [Thread (Java SE 17 & JDK 17)]
質問 # 28
Given the code fragment:
abstract sealed interface SInt permits Story, Art { default String getTitle() { return "Book Title" ; }
}
Which set of class definitions compiles?
- A. Non-sealed interface story extends SInt {}
Non-sealed interaface Art extends Sint {} - B. Sealed interface Storty extends sInt {}
Non-sealed class Art implements Sint {} - C. Public interface story extends sInd {}
Public interface Art extends SInt {} - D. Non-sealed interface story extends SInt {}
Class Art implements Sint {} - E. Interace story extends STnt {}
Interface Art extends SInt {}
正解:B
解説:
The answer is C because the code fragment given is an abstract sealed interface SInt that permits Story and Art. The correct answer is option C, which is a sealed interface Story that extends SInt and a non-sealed class Art that implements SInt. This is because a sealed interface can only be extended by the classes or interfaces that it permits, and a non-sealed class can implement a sealed interface.
Option A is incorrect because interface is misspelled as interace, and Story and Art should be capitalized as they are the names of the permitted classes or interfaces.
Option B is incorrect because public is misspelled as public, and sInd should be SInt as it is the name of the sealed interface.
Option D is incorrect because a non-sealed interface cannot extend a sealed interface, as it would violate the restriction of permitted subtypes.
Option E is incorrect because both Story and Art cannot be non-sealed interfaces, as they would also violate the restriction of permitted subtypes.
Reference:
Oracle Certified Professional: Java SE 17 Developer
Java SE 17 Developer
OCP Oracle Certified Professional Java SE 17 Developer Study Guide
Sealed Classes and Interfaces in Java 15 | Baeldung
Sealed Class in Java - Javatpoint
質問 # 29
Given the code fragment:
What is the result?
- A. 1
2
-4 - B. 2
2
0 - C. 0
B 2
C -2 - D. 1
1
1
正解:B
解説:
The code fragment uses the Collections.binarySearch method to search for the string "e3" in the list. The first search returns the index of the element, which is 2. The second search returns the index of the element, which is 0. The third search returns the index of the element, which is -4. The final result is 2. Reference: Collections (Java SE 17 & JDK 17) - Oracle
質問 # 30
Given the code fragment:
What is the result?
- A. True true false NewYear
- B. 0110
- C. False true true optional (Newyear)
- D. 010 optional (Newyear)
正解:C
解説:
The code fragment is using the stream methods allMatch, anyMatch, noneMatch, and findFirst on a list of strings called specialDays. These methods are used to perform matching operations on the elements of a stream, such as checking if all, any, or none of the elements satisfy a given predicate, or finding the first element that matches a predicate1. The predicate in this case is that the string equals "Labour" or "Halloween". The output will be:
False: because not all of the elements in specialDays are equal to "Labour" or "Halloween".
true: because at least one of the elements in specialDays is equal to "Labour" or "Halloween".
true: because none of the elements in specialDays are equal to both "Labour" and "Halloween".
Optional[NewYear]: because the first element in specialDays that matches the predicate is "NewYear", and the findFirst method returns an Optional object that may or may not contain a non-null value2.
質問 # 31
Given the code fragment:
Which action enables the code to compile?
- A. Make the regNo variable static.
- B. Make the regNo variable public
- C. Remove the regNO initialization statement.
- D. Replace thye regNo variable static
- E. Replace record with void.
正解:B
解説:
The code will compile if the regNo variable is made public. This is because the regNo variable is being accessed in the main method of the App class, which is outside the scope of the Product class. Making the regNo variable public will allow it to be accessed from outside the class. Reference: https://education.oracle.com/products/trackp_OCPJSE17, https://mylearn.oracle.com/ou/learning-path/java-se-17-developer/99487, https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html
質問 # 32
Given the code fragment:
What is the result?
- A. 1
2
-4 - B. 0
- C. 1
- D. 1
1
1 - E. 2
2
0 - F. 2
正解:F
解説:
Explanation
The code fragment uses the Collections.binarySearch method to search for the string "e3" in the list. The first search returns the index of the element, which is 2. The second search returns the index of the element, which is 0. The third search returns the index of the element, which is -4. The final result is
2. References: Collections (Java SE 17 & JDK 17) - Oracle
質問 # 33
Which statement is true?
- A. IllegalStateException is thrown if a thread in waiting state is moved back to runnable.
- B. thread in waiting state consumes CPU cycles.
- C. A thread in waiting state must handle InterrupedException.
- D. After the timed wait expires, the waited thread moves to the terminated state.
正解:C
解説:
Explanation
A thread in waiting state is waiting for another thread to perform a particular action, such as calling notify() or notifyAll() on a shared object, or terminating a joined thread. A thread in waiting state can be interrupted by another thread, which will cause the waiting thread to throw an InterruptedException and return to the runnable state. Therefore, a thread in waiting state must handle InterruptedException, either by catching it or declaring it in the throws clause. References: Thread.State (Java SE 17 & JDK 17), [Thread (Java SE 17 & JDK 17)]
質問 # 34
Given the product class:
And the shop class:
What is the result?
- A. Compilation fails
- B. Cookie 0.0 2.99
- C. Cookie 3.99 2.99
- D. An exception is produced at runtime
- E. Cookie 2.99 2.99
- F. Cookie 0.0 0.0
正解:A
解説:
The code fragment will fail to compile because the readObject method in the Product class is missing the @Override annotation. The readObject method is a special method that is used to customize the deserialization process of an object. It must be declared as private, have no return type, and take a single parameter of type ObjectInputStream. It must also be annotated with @Override to indicate that it overrides the default behavior of the ObjectInputStream class. Without the @Override annotation, the compiler will treat the readObject method as a normal method and not as a deserialization hook. Therefore, the code fragment will produce a compilation error. Reference: Object Serialization - Oracle, [ObjectInputStream (Java SE 17 & JDK 17) - Oracle]
質問 # 35
Given the directory structure:
Given the definition of the Doc class:
Which two are valid definition of the wordDoc class?
- A. Package p1, p2;
Public non-sealed class WordDoc extends Doc () - B. Package p1;
Public non-sealed class wordDoc extends Doc () - C. Package p1,
non-sealed abstract class WordDoc extends Doc () - D. Package p1;
Public final class WordDoc extends Doc () - E. Package p1, p2;
Public sealed class WordDoc extends Doc () - F. Package p1;
Public class wordDoc extends Doc ()
正解:B、D
解説:
The correct answer is A and F because the wordDoc class must be a non-sealed class or a final class to extend the sealed Doc class. Option B is incorrect because the wordDoc class must be non-sealed or final. Option C is incorrect because the wordDoc class cannot be in a different package than the Doc class. Option D is incorrect because the wordDoc class cannot be a sealed class. Option E is incorrect because the wordDoc class cannot be an abstract class. Reference: Oracle Certified Professional: Java SE 17 Developer, 3 Sealed Classes - Oracle Help Center
質問 # 36
Given the product class:
And the shop class:
What is the result?
- A. Compilation fails
- B. Cookie 0.0 2.99
- C. Cookie 3.99 2.99
- D. An exception is produced at runtime
- E. Cookie 2.99 2.99
- F. Cookie 0.0 0.0
正解:A
解説:
Explanation
The code fragment will fail to compile because the readObject method in the Product class is missing the
@Override annotation. The readObject method is a special method that is used to customize the deserialization process of an object. It must be declared as private, have no return type, and take a single parameter of type ObjectInputStream. It must also be annotated with @Override to indicate that it overrides the default behavior of the ObjectInputStream class. Without the @Override annotation, the compiler will treat the readObject method as a normal method and not as a deserialization hook. Therefore, the code fragment will produce a compilation error. References: Object Serialization - Oracle, [ObjectInputStream (Java SE 17 & JDK 17) - Oracle]
質問 # 37
Which two code fragments compile?
- A.

- B.

- C.

- D.

- E.

正解:D、E
解説:
The two code fragments that compile are B and E. These are the only ones that use the correct syntax for declaring and initializing a var variable. The var keyword is a reserved type name that allows the compiler to infer the type of the variable based on the initializer expression. However, the var variable must have an initializer, and the initializer must not be null or a lambda expression. Therefore, option A is invalid because it does not have an initializer, option C is invalid because it has a null initializer, and option D is invalid because it has a lambda expression as an initializer. Option B is valid because it has a String initializer, and option E is valid because it has an int initializer.
https://docs.oracle.com/en/java/javase/17/language/local-variable-type-inference.html
質問 # 38
......
1z1-829問題集と練習テスト(50試験問題):https://jp.fast2test.com/1z1-829-premium-file.html