Mastering Java: The Ultimate Quiz for 'Thinking in Java'

Disable ads (and more) with a membership for a one time $2.99 payment

Mastering Java: The Ultimate Quiz for 'Thinking in Java'. Dive deep into Java with multiple-choice questions. Challenge yourself with quiz questions designed to test and improve your understanding of the 'Thinking in Java' book. Get ready for your exam!

Practice this question and more.


What method in the CBox class is responsible for updating its color?

  1. public void paintControl(PaintEvent e)

  2. public void changeColor()

  3. private void updateColor()

  4. public void run()

The correct answer is: public void run()

The correct method responsible for updating the color of the CBox class is "public void run()". Option A, "public void paintControl(PaintEvent e)", is a method used to paint the control, but not specifically to update its color. Option B, "public void changeColor()", may seem like the correct answer, but it is not specified in the question if this method exists in the CBox class. Option C, "private void updateColor()", is a private method, meaning it is only accessible within the CBox class and cannot be used to update the color from outside of the class. Therefore, the most appropriate answer is D, "public void run()", as this method is responsible for running the control and can be used to update its color.