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

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

Dive into the depths of Java with our quiz based on "Thinking in Java, Fourth Edition" by Bruce Eckel. Test your knowledge, solidify concepts, and prepare for certification with challenging questions and insightful feedback.

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

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.