โ† All SCJP Flashcard Decks

Basic Flashcards

7 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Basic flashcards as text
  1. Only one of the five Component methods listed below is also a method of the class MenuItem. Which one?

    Answer: setEnabled( boolean b )

    The `setEnabled(boolean b)` method is a common method found in both the `Component` class and the `MenuItem` class. This method controls whether the component or menu item is active and can respond to user input. While other options like `setForeground`, `setVisible`, and `getSize` are `Component` methods, `MenuItem` specifically shares the `setEnabled` functionality.

  2. Which of the java.awt.Graphics class's following methods would be used to draw the outline of a rectangle in a single method call?

    Answer: drawRect()

    The `drawRect()` method of the `java.awt.Graphics` class is specifically designed to draw the outline of a rectangle using a single method call. Other methods like `fillPolygon()` and `drawPolygon()` are for drawing polygons, and `drawLine()` is for drawing individual line segments, not a complete rectangle outline.

  3. If comp is a __________, the Container methods add(Component comp) and add(String name, Component comp) will raise an IllegalArgumentException.

    Answer: window

    In AWT, `Window` objects (which include `Frame` and `Dialog`) are top-level containers and cannot be added to other `Container` objects using the `add()` methods. Attempting to add a `Window` to another `Container` will result in an `IllegalArgumentException` because `Window` objects are designed to be standalone and not nested within other components.

  4. Which one or ones of the following AWT classes are in charge of carrying out the components layout?

    Answer: FlowLayout

    `FlowLayout` and `GridBagLayout` are concrete layout manager classes in AWT that are responsible for arranging components within a container. `LayoutManager` is an interface that defines the contract for layout managers, not a class that performs layout itself. `WindowAdapter` is an adapter class for handling window events, unrelated to component layout.

  5. If a component needs to resize vertically but not horizontally, it should go in a:

    Answer: BorderLayout in the East or West location

    In a `BorderLayout`, components placed in the `EAST` or `WEST` regions will automatically resize vertically to fill the available height of the container. However, their horizontal width is typically fixed or determined by their preferred size, allowing them to resize vertically without changing horizontally. Components in `NORTH` or `SOUTH` resize horizontally, and `CENTER` resizes both ways.

  6. Which of the following best describes the order in which a component is redrawn as a result of method calls?

    Answer: invoke repaint() which invokes update(), which in turn invokes paint()

    When a component needs to be redrawn, the `repaint()` method is typically invoked. This method does not draw directly but schedules an update request. The AWT event dispatcher then calls the `update()` method, which by default clears the component's background and then calls the `paint()` method to perform the actual drawing.

  7. The following class(es)' methods can be used to create directories:

    Answer: File

    The `java.io.File` class provides methods for interacting with the file system, including creating directories. Specifically, the `mkdir()` method creates a single directory, and `mkdirs()` creates a directory along with any necessary but nonexistent parent directories. `DataOutput` and `FileDescriptor` serve different purposes, and `Directory` is not a standard Java class for this function.

How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy