1.
If a class is named Student, the class constructor name is ......
any legal Java identifier
any legal Java identifier that begins with S
StudentConstructor
Student
2.
A method is declared as public static void showResults(double d, int i). Which of the following is a correct method call?
showResults(double d, int i);
showResults(12.2, 67);
showResults(4, 99.7);
Two of these are correct.
3.
The body of a class is always written ......
in a single line, as the first statement in a class
within parentheses
between curly braces
as a method call
4.
Which of the following is a correct call to a method declared as public static void aMethod(char code)?
void aMethod();
void aMethod('V');
aMethod(char 'M');
aMethod('Q');
5.
The rules of a programming language constitute its ......
objects
logic
format
syntax
6.
An instance of a class is a(n) ......
object
procedure
method
class
7.
All Java programming statements must end with a ......
period
comma
semicolon
closing parenthesis
8.
The assignment operator in Java is ......
=
==
:=
::
9.
Which of the following is imported when creating a graphical user interface?
javax.swing
java.util
java.swing
java.graphic
10.
Which of the following is not a type of loop?
switch
while
for
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);
0 1
2
0 1 2
1
12.
What is the keyword for creating an object from a class?
this
new
create
super
13.
Which of the following controls is for writing a text on a graphical user interface?
JTextField
JLabel
JButton
JPasswordField
14.
By default a FlowLayout is position at the
left
bottom
right
center
15.
Which of the following method is use for adding a component to another component in a graphical user interface?
append
add
attach
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);
}
0
1
0
3
3
6
6
3
17.
The size of an array is 10. What will be the value of the last index of the array?
10
9
7
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");
}
3 2 12 20
20 12 2 3
1 2 3 4
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?
Employee e = new Employee(“Joseph”, “Bortey”, “20”);
Employee e = new Employee(“Joseph”, 20);
Employee e = new Employee(“Joseph”, “Bortey”);
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?
numbers[0];
numbers[4];
numbers[5];
numbers[3];