Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

NPTEL Online Certification Courses

Indian Institute of Technology Kharagpur

PROGRAMMING IN JAVA
Assignment 8
TYPE OF QUESTION: MCQ
Number of questions: 10 Total marks: 10 × 1 = 10

QUESTION 1:

What does AWT stand for in Java?

a. Applet Windowing Toolkit

b. Abstract Window Toolkit

c. Absolute Windowing Toolkit

d. None of the above

Correct Answer:

b. Abstract Window Toolkit

Detailed Solu�on:

The Abstract Window Toolkit (AWT) is Java's original pla�orm-dependent windowing, graphics, and user-
interface widget toolkit, preceding Swing.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 2:

When we invoke repaint() for a java.awt.Component object, the AWT invokes which of the
following method ?

a. draw( )

b. show( )

c. update( )

d. none of the men�oned

Correct Answer:

c. update( )

Detailed Solu�on:

The repaint() method calls automa�cally update() method and in turn update() method calls
paint() method.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 3:

Which is/are used to create a Frame?

1. By creating the object of Frame class (association)

2. By extending Frame class (inheritance)

a. Only 1

b. Only 2

c. Both

d. None

Correct Answer:

c. Both

Detailed Solu�on:

A Frame object can be created using the Frame class itself as well as extending the Frame class.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 4:

Which AWT concept allows you to handle events such as button clicks or mouse movements?

a. Event Handling

b. Component Interac�on

c. Process Management

d. GUI Processing

Correct Answer:

a. Event Handling

Detailed Solu�on:

Event Handling in AWT enables the response to user ac�ons, such as buton clicks or mouse movements,
in a graphical user interface.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 5:

Which of the following methods can be used to change the size of a java.awt.Component object?

1. dimension()

2. setSize()

3. area()

4. size()

5. resetSize()

a. 1, 2, 3 & 5

b. 4 & 5

c. 1, 2 & 5

d. only 2

Correct Answer:

d. only 2

Detailed Solu�on:

The method setSize() can only be used to change the size of a component.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 6:

Which of the following is TRUE regarding checkbox and radio button?

a. Checkbox is used for single selec�on item whereas radio buton is used for mul�ple selec�on.

b. Checkbox is used for mul�ple selec�on items whereas radio buton is used for single selec�on.

c. Both are used for mul�ple as well as single item selec�on.

d. Checkbox is the same as radio butons.

Correct Answer:

b. Checkbox is used for mul�ple selec�on items whereas radio buton is used for single selec�on.

Detailed Solu�on:

Checkbox is used for mul�ple selec�on items whereas radio buton is used for single selec�on. For
example, if a form is asking for your favorite hobbies, there might be mul�ple correct answers to it, in
that case checkbox is preferred. And if a form is asking about gender, there must be only one true op�on
among the mul�ple choices, in that case radio butons are used.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 7:

How is AWT different from Swing in Java?

a. AWT is for web applica�ons, Swing is for desktop applica�ons

b. AWT uses lightweight components, Swing uses heavyweight components

c. AWT is newer than Swing

d. AWT and Swing are synonyms, used interchangeably

Correct Answer:

b. AWT uses lightweight components, Swing uses heavyweight components

Detailed Solu�on:

AWT components are pla�orm-dependent and use na�ve components, whereas Swing components are
implemented in Java and are pla�orm-independent.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 8:

What is the primary purpose of AWT components in GUI programming?

a. To perform mathema�cal calcula�ons

b. To interact with databases

c. To create graphical user interfaces

d. To handle network communica�ons

Correct Answer:

c. To create graphical user interfaces

Detailed Solu�on:

AWT components provide the building blocks for crea�ng graphical user interfaces (GUIs) in Java
applica�ons.
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 9:

What will be the output of the Java code given below?

import java.awt.*;
import java.awt.event.*;

public class ButtonExample extends Frame {


public static void main(String[] args) {
ButtonExample frame = new ButtonExample();
Button b = new Button("NPTEL – Programming in Java");
b.setBounds(30, 50, 80, 30);
frame.add(b);
frame.setSize(300, 200);
frame.setLayout(null);
frame.setVisible(true);
}
}

a. A frame with a buton "NPTEL – Programming in Java" at coordinates (30, 50)

b. Compila�on error

c. An empty frame with no buton

d. A frame with a buton, but not at the specified coordinates

Correct Answer:

a. A frame with a buton "NPTEL – Programming in Java" at coordinates (30, 50)

Detailed Solu�on:

The code creates a frame and adds a buton with the label "NPTEL – Programming in Java" at coordinates
(30, 50).
NPTEL Online Certification Courses
Indian Institute of Technology Kharagpur

QUESTION 10:

What is the layout manager used in the Java code given below?

import java.awt.*;
import java.awt.event.*;

public class GridLayoutExample extends Frame {


public static void main(String[] args) {
GridLayoutExample frame = new GridLayoutExample();
Button b1 = new Button("Button 1");
Button b2 = new Button("Button 2");
Button b3 = new Button("Button 3");
frame.add(b1);
frame.add(b2);
frame.add(b3);
frame.setLayout(new GridLayout(2, 2));
frame.setSize(300, 200);
frame.setVisible(true);
}
}

a. Border Layout

b. Flow Layout

c. Grid Layout

d. Card Layout

Correct Answer:

c. Grid Layout

Detailed Solu�on:

The code sets the layout manager of the 1frame to a 2x2 grid layout using frame.setLayout(new
GridLayout(2, 2)).

You might also like