Mixed Deck — All 1Z0-811 Topics Flashcards
100 cards from real 1Z0-811 practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 20 Mixed Deck — All 1Z0-811 Topics flashcards as text
Which approach is most effective for problem-solving in Object-Oriented Programming?
Answer: Systematic analysis followed by evidence-based decision making
Systematic, evidence-based approaches lead to more reliable solutions than ad hoc methods.
What is the output of `int x = 5; System.out.println(x++);`?
Answer: 5
The post-increment operator `x++` returns the current value of x (5) before incrementing it to 6.
What is the return type of `Map.entrySet()`?
Answer: Set>
`Map.entrySet()` returns a `Set>` containing all key-value pair entries in the map.
Which directory inside a module source tree conventionally holds the `module-info.java` file?
Answer: The root of the module's source directory
`module-info.java` is placed at the root of the module's source tree, at the same level as the top-level package directories.
Which interface in the Java Collections Framework represents a collection of elements that allows for duplicates and maintains insertion order?
Answer: List
The `List` interface in the Java Collections Framework represents an ordered collection (sequence) of elements. It explicitly allows for duplicate elements and maintains the insertion order of elements. In contrast, `Set` does not allow duplicates, `Queue` maintains order for processing, and `Map` stores key-value pairs.
Which of the following correctly describes a labeled break statement?
Answer: It breaks from a specified outer loop
A labeled break exits the loop (or block) associated with the specified label, not just the innermost one.
Which class do all Java classes implicitly extend if no explicit superclass is declared?
Answer: java.lang.Object
Every Java class implicitly extends `java.lang.Object` when no other superclass is specified.
Which of the following access modifiers can be used on a top-level class declaration?
Answer: public or package-private only
Top-level classes can only be `public` or package-private (no modifier); `private` and `protected` are not allowed at the top level.
Can a `static` method access instance variables directly?
Answer: No, because static methods belong to the class, not an instance
Static methods do not have access to instance variables directly because they are not associated with any object instance.
What is the result of `true || false && false` in Java?
Answer: true
Due to operator precedence, `&&` is evaluated before `||`, so the expression becomes `true || (false && false)` = `true || false` = `true`.
What happens when you use `requires transitive com.example.util;` in a module descriptor?
Answer: Modules that require your module automatically also read com.example.util
`requires transitive` implies that any module depending on your module implicitly also depends on `com.example.util`, enabling implied readability.
Which of the following is NOT a valid identifier in Java?
Answer: 2ndItem
Java identifiers cannot begin with a digit; '2ndItem' is invalid because it starts with '2'.
What is the -classpath option used for when running the java command?
Answer: To set the path for finding Java libraries and classes during runtime
When running the `java` command, the `-classpath` (or `-cp`) option is used to specify the path where the Java Virtual Machine (JVM) should look for user-defined classes and packages. This path includes directories containing `.class` files and JAR files, ensuring that the JVM can locate all necessary components for the application to execute correctly at runtime.
Which `java` command-line option sets the module path?
Answer: --module-path
`--module-path` (or `-p`) specifies where the JVM looks for named modules, analogous to `-classpath` for the legacy class path.
Which access modifier makes a member accessible only within its own class?
Answer: private
`private` restricts visibility strictly to the declaring class itself.
What is the role of the `java.base` module in the Java module system?
Answer: It is the foundational module that every other module implicitly requires
`java.base` defines the core JDK APIs and is implicitly required by all modules; you never need to declare `requires java.base`.
In Java, where can a local variable be declared?
Answer: Anywhere inside a block where it is needed
Local variables in Java can be declared anywhere inside a block, but they must be initialized before use.
How can you create a class that cannot be subclassed?
Answer: By using the final keyword
To prevent a class from being subclassed, you must use the `final` keyword in its declaration. A `final` class cannot be extended, meaning no other class can inherit from it. This is often used for security reasons or to ensure immutability and prevent unintended modifications to class behavior.
Which of the following is true about the "switch" statement in Java?
Answer: switch statements can be used with String values starting from Java SE 7
Prior to Java SE 7, `switch` statements could only evaluate expressions of type `byte`, `short`, `char`, or `int`, or their corresponding wrapper classes, and enums. However, with Java SE 7, the capability was extended to allow `String` objects as the expression in a `switch` statement. This enhancement provides more flexibility and cleaner code for string-based conditional logic.
What is the output of `System.out.println(" hello ".strip())`?
Answer: "hello"
`String.strip()` removes leading and trailing whitespace (including Unicode whitespace), returning "hello".