Create Software Components 

Using Java Level 2



Course Info




Java Demos




    Multiple Choice Quiz 1

Pre-test Practice

There are 40 questions 

(If you take this quiz on Blackboard you will be timed and receive a test score.  

This will be good practice for the real online test)

Question 1.         

A syntax error is signalled by the

(a)   compiler

(b)   editor

(c)   linker

(d)   run-time system

Question 2.         

Which type of code is editable?

(a)   executable

(b)   source

(c)   object

(d)   library

Question 3.         

A run-time error is ALWAYS caused by

(a)   incorrect logic

(b)   incorrect syntax

(c)   incorrect linking

(d)   division by zero

Question 4.         

When a program is running the value of a variable

(a)   cannot be changed

(b)   cannot be used

(c)   is hidden

(d)   can be changed

Question 5.         

The type of a function/procedure/module is determined by

(a)   its arguments

(b)   the value returned

(c)   its name

(d)   the address returned

Question 6.         

Typically a variable defined in a function/procedure/module has

(a)   scope for the whole file

(b)   global scope

(c)   local scope

(d)   returns its value between calls

Question 7.         

A program construct used for selection is

(a)   if...else

(b)   for loop

(c)   while loop

(d)   a sequence

Question 8.         

What is the result of the the following expression


(a)   22

(b)   25

(c)   40

(d)   52

Question 9.         

An argument passed by reference passes

(a)   a global variable

(b)   a constant

(c)   a value

(d)   an address

Question 10.         

Test results are proved by comparison of

(a)   logical to syntax errors

(b)   expected to actual input

(c)   logical to run time errors

(d)   expected to actual output

Question 11.         

The switch construct is used for

(a)   sequence

(b)   selection

(c)   iteration

(d)   boolean operations

Question 12.         

How many times will the following loop execute?

for (j=1; j<=10; j=j+1) 

(a)   1

(b)   10

(c)   9

(d)   never

Question 13.         

What is the result after execution of the following code if a is 10, b is 5 and c is 10?

if ((a>b) && (a<=c))

       a = a + 1


       c = c + 1

(a)   a = 10, c = 10

(b)   a = 11, c = 10

(c)   a = 10, c = 11

(d)   a = 11, c = 11

Question 14.         

Which one of the following events is handled by an ActionListener?

(a)   mouse dragged over a component

(b)   button clicked on a component

(c)   key pressed

(d)   window closed

Question 15.         

Which one of the following uses the correct syntax to include an applet called ButtonText in a HTML page?

(a)   <p><Applet="" width = 300 height = 250></p>

(b)   <p><Applet code="" width = 300 height = 250></p>

(c)   <p><Applet code="ButtonText.class" width = 300 height = 250></p>

(d)   <p><Applet="ButtonText.class" width = 300 height = 250></p>

Question 16.         

Which one of the following is FALSE?


(a)   anything written after / in on a line will be ignored by the Java compiler 

(b)   anything written after // in on a line will be ignored by the Java compiler 

(c)   anything written between  /** and */ will be ignored by the Java compiler 

(d)   anything written between  /* and */ will be ignored by the Java compiler 

Question 17.         

What is the purpose of the following code fragment?


void init()


...some code in here



(a)   A required method to start an applet for the first time

(b)   A method all user-defined classes must have

(c)   A place to declare variables

(d)   A required method in an application

Question 18.         

Which of the following is FALSE?  Java packages

(a)   are sets of source code files

(b)   are sets of predefined classes

(c)   allow us to access predefined classes using the import statement

(d)   are sets of bytecode class files

Question 19.         

The extends keyword

(a)   creates an instance of a class

(b)   specifies a class is independent

(c)   specifies a class is a superclass of another class

(d)   specifies a class is a subclass of another class

Question 20.         

A variable declared in a class but outside any method is called a

(a)   local variable

(b)   instance variable

(c)   static variable

(d)   constant

Question 21.         

Which of the following methods directly uses an RGB color

(a)   setColor(

(b)   setColor(

(c)   setForeground(255,0,0,)

(d)   Color c

Question 22.         

The paint method is

(a)   used for painting graphic shapes

(b)   used by an application for painting components

(c)   used by an applet for painting components

(d)   a required application method

Question 23.         

Examine the following method.  

 public int anyMethod (int k) {

k= k+ 1;

return k;


Which of the following statements is FALSE?

(a)   anyMethod(b) passes the value held by the variable b.

(b)   anyMethod(b) passes the address of the variable b.

(c)   anyMethod returns the value of the variable k

(d)   the variable k is a local variable

Question 24.         

Which of the following is FALSE?  Reserved words in Java

(a)   cannot be used as names for variables

(b)   cannot be used for method names

(c)   can be used for naming constants

(d)   are part of the Java programming language

Question 25.         

Which of the following statement is FALSE?

(a)   Classes have behavior (methods) and attributes (data)

(b)   class attributes in Java are implemented as variables

(c)   attributes represent an object's state

(d)   attributes are local variables declared inside methods

Question 26.         

The break statement is used

(a)   in a switch statement to stop cases running together

(b)   to halt program execution

(c)   to exit a method

(d)   in a switch statement to go to the default case

Question 27.         

The NOT boolean operator is represented by 

(a)   &&

(b)   !

(c)   ^

(d)   || 

Question 28.         

A dialog box which is modal

(a)   allows interaction with other windows of its parent application

(b)   does not allow interaction with other windows of its parent application

(c)   is hidden

(d)   is never used in java

Question 29.         

A panel is

(a)   a component

(b)   a window with a title bar

(c)   is used to create dialog boxes

(d)   a container used to organise components

Question 30.         

A Choice is

(a)   another name for a list box

(b)   another name for a combo box

(c)   another name for a radio button group

(d)   another name for a check box group

Question 31.         

A layout manager is used

(a)   for containing components

(b)   for laying out applets in a web page

(c)   for organising menu items

(d)   for arranging components in a container in a particular way

Question 32.         

The layout manager that arranges components in rows is called

(a)   FlowLayout

(b)   BorderLayout

(c)   GridLayout

(d)   BoxLayout

Question 33.         

The default layout manager for an applet is

(a)   FlowLayout

(b)   BorderLayout

(c)   GridLayout

(d)   BoxLayout

Question 34.         

What will be the result of the following expression?

String s1 = new String ("Hello");


(a)   true

(b)   false

(c)   compiler error

(d)   run time error

Question 35.         

Which of the following Graphics methods is used for drawing the outline of a circle?

(a)   fillOval

(b)   drawCircle

(c)   fillCircle

(d)   drawOval 

Question 36.         

Which of the following Graphics methods draws a horizontal line?

(a)   drawLine(100,0,100,0)

(b)   drawLine(0,100,0,100)

(c)   drawLine(0,0,100,100)

(d)   drawLine(0,0,100,0)

Question 37.         

Which of the following correctly creates a new instance of a swing button?

(a)   JButton aNewButton = JButton("click me");

(b)   JButton = new JButton("click me");

(c)   JButton aNewButton = new JButton("click me");

(d)   JButton aNewButton = new JButton;

Question 38.         

Examine the following code

public class MyClass {

  char ch

  public void aMethod(int b) {

        b = b + 1;



Which of the following statement is FALSE?

(a)   ch is an instance variable

(b)   b is a local variable

(c)   b is an instance variable

(d)   the scope of b is within the method called aMethod

Question 39.         

Which one of the following would be a suitable type for a variable  that stores a personís bank account amount? 

(a)   boolean

(b)   int

(c)   float

(d)   String  

Question 40.         

What will the following statement sequence output?


int a = 10;

int b = -10;

if (a==b)



System.out.println("Not Equal");  

(a)  Not Equal

(b)   Equal

(c)  The program doesn't compile because = = cant be used here

(d)   Equal Not equal



  Site Home 

Java Home   


Course Info





Scheme of Work





Learning Center

Web Materials


Java Demos



Lecture Materials

Tutorials & Notes





Site Home


Unit Home

ADR 2002