โ† All 1Z0-811 Flashcard Decks

Java Language Fundamentals Flashcards

5 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 5 Java Language Fundamentals flashcards as text
  1. What will be the output of the following code snippet? int a = 10; int b = 5; System.out.println(a % b);

    Answer: 0

    The '%' operator in Java is the modulo operator, which calculates the remainder of a division. In the given code, `a` is 10 and `b` is 5. When 10 is divided by 5, the result is 2 with a remainder of 0. Therefore, `a % b` evaluates to 0.

  2. 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.

  3. What is the result of the following code? int x = 5; x += 3; System.out.println(x);

    Answer: 8

    The code initializes an integer variable `x` with the value 5. The line `x += 3;` is a shorthand assignment operator equivalent to `x = x + 3;`. This operation adds 3 to the current value of `x`, so `x` becomes `5 + 3`, which is 8. Finally, `System.out.println(x)` prints the updated value of `x`, which is 8.

  4. How does Java handle integer division when both operands are integers?

    Answer: It performs integer division and truncates the result

    In Java, when both operands of a division operation are integers, the division performed is integer division. This means that any fractional part of the result is discarded or truncated, effectively rounding towards zero. For example, `7 / 3` would result in `2`, not `2.33` or `3`.

  5. Which of the following statements about Java methods is true?

    Answer: A method can be overloaded with different parameter types

    Method overloading in Java allows a class to have multiple methods with the same name, provided they have different parameter lists. This difference can be in the number of parameters, the data types of the parameters, or the order of the parameter types. The return type alone is not sufficient to overload a method, but different parameter types enable distinct method signatures.