Untitled Quiz
32 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the purpose of the statement c %= 5 in the code int c = 8; c++; ++c; c %= 5;?

  • To assign the value of c as the remainder when divided by 5 (correct)
  • To add 5 to the value of c
  • To check if c is greater than 5
  • To multiply c by 5
  • Why would you use method overloading in programming?

  • To improve code readability and usability with different parameters (correct)
  • To reduce the number of methods in the code
  • To ensure a method can only be called from within a class
  • To create methods with different return types for the same operation
  • Which of the following parameters can be passed to the method displayValue(int value)?

  • Characters, integers, or strings
  • Any data type
  • Floats and doubles
  • Only integers (correct)
  • What will be the output if x = 25, y = 8; x += y++; is executed?

    <p>x = 34, y = 9</p> Signup and view all the answers

    What is the result of the expression result = d % a * c + a % b + a; with a=4, b=12, c=37, d=51?

    <p>119</p> Signup and view all the answers

    Which method correctly outputs float values?

    <p>Using <code>%f</code> as the format specifier</p> Signup and view all the answers

    When should you use the static keyword with methods?

    <p>When you want the method to be accessible without an object instance</p> Signup and view all the answers

    What does the expression if (gender == 1 && age >= 65) check for?

    <p>If both conditions are true simultaneously</p> Signup and view all the answers

    What will be the resulting value of 'charges' after executing the given expression with time set to 180 and rate set to 7.00?

    <p>$21.00$</p> Signup and view all the answers

    What is the outcome when arrays 'x[]' and 'y[]' are swapped according to the provided code?

    <p>x[] = {36, 78, 12, 24}, y[] = {23, 55, 83, 19}</p> Signup and view all the answers

    What does the declaration of a static field signify within a class?

    <p>Only one copy of the field in memory.</p> Signup and view all the answers

    When 'System.out.println(account)' is executed and 'account' is a BankAccount object, what happens?

    <p>The BankAccount object's toString method will be implicitly called.</p> Signup and view all the answers

    What occurs if the 'this' variable is not the first statement in a constructor?

    <p>A compiler error will result if it is not the first statement of the constructor.</p> Signup and view all the answers

    In which stage is polymorphism resolved in programming?

    <p>Execution</p> Signup and view all the answers

    What does the binary search algorithm achieve in terms of efficiency compared to the sequential search?

    <p>It will cut the portion being searched in half each time it fails to locate the target value.</p> Signup and view all the answers

    What is an implication of the use of the 'this' keyword in a constructor?

    <p>It designates the instance of the current class.</p> Signup and view all the answers

    Which of the following is a valid declaration for a ragged array with five rows but no columns?

    <p>int[][] ragged = new int[5][];</p> Signup and view all the answers

    What will happen when executing the given code with array initialization?

    <p>The code contains a syntax error and will not compile.</p> Signup and view all the answers

    What will the variable contain after executing the given code?

    <p>The lowest value in the numbers array.</p> Signup and view all the answers

    Which of the following for-loops is valid given String[] names = {"abc", "def", "ghi", "jkl"};?

    <p>System.out.println(names[i].length());</p> Signup and view all the answers

    The code that might throw an exception must be enclosed in a ___?

    <p>try block</p> Signup and view all the answers

    What is e in the catch block below?

    <p>The name of the catch block's exception parameter.</p> Signup and view all the answers

    What is an uncaught exception?

    <p>An exception that occurs for which there are no matching catch clauses.</p> Signup and view all the answers

    What does the throws clause of a method specify?

    <p>Specifies the exceptions a method throws.</p> Signup and view all the answers

    Which method is used to serialize objects as XML in JAXB?

    <p>marshal</p> Signup and view all the answers

    Which method displays a dialog box for user input?

    <p>showInputDialog</p> Signup and view all the answers

    What component provides fundamental attributes and behaviors for a window in Java?

    <p>JFrame</p> Signup and view all the answers

    Which method is used to add a JLabel to a JFrame?

    <p>add</p> Signup and view all the answers

    Which JFrame constant indicates that the program should terminate on window close?

    <p>EXIT_ON_CLOSE</p> Signup and view all the answers

    Which option best describes the steps for setting up event handling in a GUI component?

    <p>Create a handler class, implement an event-listener interface, and register it.</p> Signup and view all the answers

    When using a JPasswordField, what event is generated upon pressing Enter?

    <p>ActionEvent</p> Signup and view all the answers

    In what way does a JRadioButton differ from a JCheckBox?

    <p>Several JRadioButtons are grouped together and are mutually exclusive.</p> Signup and view all the answers

    Study Notes

    Question 1

    • Equivalent code for if (gender == 1) { if (age >= 65) { + +seniorFemales; } } is if (gender == 1 && age >= 65) { ++seniorFemales; }

    Question 2

    • Overloaded methods: max methods with different parameter types (int, double)

    Question 3

    • Correct code for calling public void displayValue(int value) is int x = 7; displayValue(x);

    Question 4

    • Value of c at the end of int c = 8; c++; ++c; c %= 5; is 0

    Question 5

    • Values of x and y after executing int x = 25, y = 8; x += y++; are x=33, y=9

    Question 6

    • Value of result after result = d % a * c + a % b + a; with a=4, b=12, c=37, d=51 is 119

    Question 7

    • Keyword that indicates the main method can be called without creating an object is static

    Question 8

    • Format specifier for float or double values is %f

    Question 9

    • Statement ensuring temp is between 0 and 100 (inclusive) is if (temp >= 0 && temp <= 100)

    Question 10

    • Value of charges after charges = time >= 119 ? rate * 2: time / 60.0 * rate; with time = 180 and rate = 7.00 is 21.00

    Question 11

    • Swapping elements of arrays x[] and y[] results is x[] = {36, 78, 12, 24}, y[] = {23, 55, 83, 19}

    Question 12

    • Declaring a field static means there is only one copy of the field in memory for all objects of the class.

    Question 13

    • Calling System.out.println(account) (where account is a BankAccount object) implicitly calls the toString method of the BankAccount object.

    Question 14

    • If the this variable is not the first statement in a constructor, it will likely cause a compiler error. The this keyword references the current object being constructed, and it's unusual to use it within a constructor after other statements have already been executed in an instance.

    Question 15

    • Polymorphism is handled during execution.

    Question 16

    • Binary search cuts the portion of the array being searched in half each time it fails to locate the value.

    Question 17

    • Valid declaration for a ragged array with 5 rows but no columns: int[][] ragged = new int[5][];

    Question 18

    • Executing code with array initialization and does not produce an error. Initialization values are likely default values of 0.

    Question 19

    • Value of variable after code execution is usually the lowest value in an array.

    Question 20

    • Valid for-loop for String[] names = {"abc", "def", "ghi", "jkl"}; is System.out.println(names[i].length());

    Question 21

    • Code that might throw an exception must be enclosed in a try block.

    Question 22

    • In the catch block, e is the exception parameter, and specifically it is usually a specific exception type that occurred.

    Question 23

    • An uncaught exception occurs when an exception happens but there is no catch block in the code to handle the specific type of exception.

    Question 24

    • The throws clause of a method specifies the exceptions that the method might throw.

    Question 25

    • A checked exception is an exception that must be declared in the method signature using the throws keyword.

    Question 26

    • The throw statement is used to throw an exception. Using the throw statement throws an exception.

    Question 27

    • The class that is not used for file input is Formatter

    Question 28

    • setIn, setOut, and setErr redirect standard input, output, and error streams.

    Question 29

    • An absolute path starts from the root directory.

    Question 30

    • The static method isDirectory returns a boolean indicating if the path is a directory.

    Question 31

    • Scanner scanner = new Scanner(Paths.get("test.txt")); opens a text file for input.

    Question 32

    • A serialized object is an object represented in memory that is saved to, and retrieved from a file using a method.

    Question 33

    • The method marshal serializes objects as XML in JAXB.

    Question 34

    • The method showInputDialog displays a dialog box to gather input.

    Question 35

    • JFrame provides the basic attributes and behaviors of a window.

    Question 36

    • The method add adds a JLabel to a JFrame.

    Question 37

    • EXIT_ON_CLOSE is the JFrame constant that indicates the program terminates when the window is closed by the user.

    Question 38

    • Steps for setting up event handling in GUI: 1. Create a class that represents event handler. 2. Implement an appropriate event-listener interface. 3. Register the event handler.

    Question 39

    • When pressing Enter in a JPasswordField the ActionEvent and ActionListener interface is used.

    Question 40

    • A JRadioButton is different from a JCheckBox because JRadioButtons are usually mutually exclusive while JCheckBox checks can be selected independently.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    More Like This

    Untitled Quiz
    6 questions

    Untitled Quiz

    AdoredHealing avatar
    AdoredHealing
    Untitled Quiz
    37 questions

    Untitled Quiz

    WellReceivedSquirrel7948 avatar
    WellReceivedSquirrel7948
    Untitled Quiz
    55 questions

    Untitled Quiz

    StatuesquePrimrose avatar
    StatuesquePrimrose
    Untitled Quiz
    50 questions

    Untitled Quiz

    JoyousSulfur avatar
    JoyousSulfur
    Use Quizgecko on...
    Browser
    Browser