Share
Java Programming MULTIPLE CHOICE QUESTIONS

1.

If a class is named Student, the class constructor name is ......

A.

any legal Java identifier

B.

any legal Java identifier that begins with S

C.

StudentConstructor

D.

Student

2.

A method is declared as public static void showResults(double d, int i). Which of the following is a correct method call?

A.

showResults(double d, int i);

B.

showResults(12.2, 67);

C.

showResults(4, 99.7);

D.

Two of these are correct.

3.

The body of a class is always written ......

A.

in a single line, as the first statement in a class

B.

within parentheses

C.

between curly braces

D.

as a method call

4.

Which of the following is a correct call to a method declared as public static void aMethod(char code)?

A.

void aMethod();

B.

void aMethod('V');

C.

aMethod(char 'M');

D.

aMethod('Q');

5.

The rules of a programming language constitute its ......

A.

objects

B.

logic

C.

format

D.

syntax

6.

An instance of a class is a(n) ......

A.

object

B.

procedure

C.

method

D.

class

7.

All Java programming statements must end with a ......

A.

period

B.

comma

C.

semicolon

D.

closing parenthesis

8.

The assignment operator in Java is ......

A.

=

B.

==

C.

:=

D.

::

9.

Which of the following is imported when creating a graphical user interface?

A.

javax.swing

B.

java.util

C.

java.swing

D.

java.graphic

10.

Which of the following is not a type of loop?

A.

switch

B.

while

C.

for

D.

do while

11.

What will be the output when the following code is run?


int i = 2;

do{
      System.out.println(i);
      i++;
}while(i<2);

A.

0 1

B.

2

C.

0 1 2

D.

1

12.

What is the keyword for creating an object from a class?

A.

this

B.

new

C.

create

D.

super

13.

Which of the following controls is for writing a text on a graphical user interface?

A.

JTextField

B.

JLabel

C.

JButton

D.

JPasswordField

14.

By default a FlowLayout is position at the

A.

left

B.

bottom

C.

right

D.

center

15.

Which of the following method is use for adding a component to another component in a graphical user interface?

A.

append

B.

add

C.

attach

D.

join

16.

What will be the output when the following code is run?


int[] numbers = new int[2];
numbers[0] = 1;
numbers[1] = 2;
for(int i=0;i<2;i++){
    System.out.println(numbers[i]*3);
}

A.

0
1

B.

0
3

C.

3
6

D.

6
3

17.

The size of an array is 10. What will be the value of the last index of the array?

A.

10

B.

9

C.

7

D.

6

18.

What will be the out when the follow code is run?


int[] numbers = new int[4];
numbers[0] = 1;
numbers[1] = 2;
numbers[2] = 3;
numbers[3] = 4;
		
int[] data = new int[4];
data[0] = 3;
data[1] = 1;
data[2] = 4;
data[3] = 5;
for(int i=0;i<4;i++){
System.out.print(numbers[i]*data[i]+" \n");
}

A.

3 2 12 20

B.

20 12 2 3

C.

1 2 3 4

D.

5 4 1 3

19.

The constructor of a class is defined as:


public Employee(String fn, String ln, int age){
       this.fn = fn;
       this.ln = ln;
       this.age = age;
}

Which of the following is the correct way of creating a new object of the class?

A.

Employee e = new Employee(“Joseph”, “Bortey”, “20”);

B.

Employee e = new Employee(“Joseph”, 20);

C.

Employee e = new Employee(“Joseph”, “Bortey”);

D.

Employee e = new Employee(“Joseph”, “Bortey”, 20);

20.

An array is declared as:


int[] numbers = new int[5];

Which of the following lines of code will produce an error?

A.

numbers[0];

B.

numbers[4];

C.

numbers[5];

D.

numbers[3];

SponsoredAdvertise