Java Graphics Fundamentals - Quiz Explanation

The correct answers are indicated below, along with the text that explains the correct answers.
 
1. What method in the Graphics class do you use to draw rectangles?
Please select the best answer.
  A. drawRectangle()
  B. drawRect()
  C. drawSquare()
  The correct answer is B.The drawRect() method in the Graphics class is used to draw rectangles. There are no methods named drawRectangle() and drawSquare() in the Graphics class.


2. If you want to display a scanned photograph in a Java applet, what image format is best to use?
Please select the best answer.
  A. JPEG
  B. GIF
  C. Windows bitmap
  The correct answer is A.
JPEG is the best image format to use for scanned photographs because it is specifically optimized to compress the size of photographic images. The GIF image format is geared more toward non-photographic images such as line art. Java does not directly support the Windows bitmap image format.

3. What method in the Applet class do you use to load an image?
Please select the best answer.
  A. loadImage()
  B. openImage()
  C. getImage()
  The correct answer is C.
The getImage() method in the Applet class is used to load an image.
There are no methods named loadImage() and openImage() in the Applet class.

4. Which one of the following lines of code properly invokes a method in the Graphics class to draw an image stored in the Image object named img at the position (10, 20)?
Please select the best answer.
  A. drawImage(img, 10, 20);
  B. drawImage(img, 10, 20, this);
  C. paintImage(img, 10, 20);
  The correct answer is B.
A is incorrect because the required fourth parameter, an ImageObserver object, is missing. There is no such method as paintImage() in the Graphics class