Sunteți pe pagina 1din 7

Choose the answer that better reflects the characteristics of the Java programmi

ng language:
A
Complex and Interpreted
B
Portable and procedural
C
Portable and object oriented
D
Interpreted and procedural
Response was: C
Correct Correct (1 mark)
Question 2 (1 mark) Attempt 1
(You can choose more than one option). The java interpreter:
A
translates the Java source code into machine code
B
links the object file with a standard set of routines
C
makes an executable program from the Java source program
D
translates the Java bytecodes and executes the program
Response was: A and D
Wrong Incorrect (0 mark)
the Java interpreter interprets bytecodes
Question 3 (1 mark) Attempt 1
Select the true statements about comments (you can choose more than one option)
A
all characters between /* and */ are ignored
B
all characters from /* to the end of the file are ignored
C
comments alter the way the program runs
D
all characters between // and // are ignored
Response was: B
Wrong Incorrect (0 mark)
you should read the corresponding section of the notes
Question 4 (1 mark) Attempt 1
Consider the identifiers:
4alph
got____it
A
B
C
D

They are both legal


They are both illegal
The first is legal, but the second one is not
The second is legal, but the first one is not

Response was: D
Correct Correct (1 mark)
Question 5 (1 mark) Attempt 1
(You can choose more than one option). Indicate what mistakes have been made in
the following code:
public class HelloWorld {
public static void main(String args[]) {
String message = Hello there world;
System.out.println(message);

}
}
A
B
C
D

you cannot print a variable using System.out.println()


the format of the output text is wrong
there is a missing semi-colon
You must use the keyword "new" when defining a String value

Response was: B
Correct Correct (1 mark)
Question 6 (1 mark) Attempt 1
When a Java program contains logic errors (eg. producing incorrect results) it _
______ a/an ______________
A
none of the above
B
generates, runtime error
C
displays, compilation error
D
throws, Exception
Response was: B
Wrong Incorrect (0 mark)
The java compiler/interpreter do not handle issues releating to flawed programme
r logic
Question 7 (1 mark) Attempt 1
In order to store the number 9.25f, what type of variable would you need (choose
the most appropriate type):
A
a double variable
B
a String variable
C
an long variable
D
an int variable
E
a float variable
Response was: C
Wrong Incorrect (0 mark)
Which type that handles values with decimal places that are marked with an 'f' a
t the end?
Question 8 (1 mark) Attempt 1
A program needs to declare a variable 'passengerCount' that is initialised to th
e value 0 and which may be changed later. Fill in the blanks:
___________ passengerCount = __________;
A
B
C
D

final int, "0"


int, 0
int, "0"
final int, 0

Response was: B
Correct Correct (1 mark)
Question 9 (1 mark) Attempt 1
After the following statements what is the value of c:

int a = 2;
int b = 5;
int c;
a
c
a
c

=
=
=
=

a + b + b;
b - 1;
a - c;
a;
A
B
C
D

4
5
6
8

Response was: D
Correct Correct (1 mark)
Question 10 (1 mark) Attempt 1
When a program refers to a reference variable the computer retrieves its _______
__
A
object
B
value
C
address
D
identifier
Response was: D
Wrong Incorrect (0 mark)
Remember the difference between primitive and reference-type variables.
Question 11 (1 mark) Attempt 1
Given the strings "hello" and "world", what is the result of the expression "hel
lo" + "world":
A
"hello world"
B
"helloworld"
C
"hello+world"
D
nothing - you cannot use the '+' operator with Strings
Response was: B
Correct Correct (1 mark)
Question 12 (1 mark) Attempt 1
What output is produced by the following statement?
System.out.println("Billy-Bob".compareTo("Billy"));
A
B
C
D

zero
false
a positive value
a negative value

Response was: C
Correct Correct (1 mark)
Question 13 (1 mark) Attempt 1

What is the value of the following


21 % 3 * 4 + 7
A
B
C
D

11
7
91
35

Response was: B
Correct Correct (1 mark)
Question 14 (1 mark) Attempt 1
Which one of the following set of values makes True the expression
(!X && Y) && (!X || Z)?
A
X = false, Y = true, Z = false
B
X = true, Y = true, Z = true
C
X = false, Y = false, Z = true
D
X = true, Y = false, Z = true
Response was: C
Wrong Incorrect (0 mark)
Both expressions between brackets must be true
Question 15 (1 mark) Attempt 1
For the following section of code:
if (A < 10)
System.out.println("Hello There");
If A has the value of 10 what will be the output: (assuming that the int variabl
e A has been declared previously)
A
the string "Hello There"
B
it will print a blank line
C
segment does not run due to a compilation error
D
nothing at all
Response was: D
Correct Correct (1 mark)
Question 16 (1 mark) Attempt 1
Given the following segment:
if (test_1)
statement_1;
else
if (test_2)
if (test 3)
statement_3;
else
statement_2;
only one of the following choices is true; which one?
A
One of the statements will be always executed
B
It is possible that no statement is executed
C
If test_1 is true, statement_2 and statement_3 may still be exec

uted
D

If test_1 is false, either statement_2 or statement_3 are execut

ed
Response was: D
Wrong Incorrect (0 mark)
One of the statements is always executed
Question 17 (1 mark) Attempt 1
If variable is positive and less than 50 I want to print "Success", otherwise I
want to print "Failure". The code should be:
A
if (variable > 50 && variable > 0)
System.out.println("Success!");
else
System.out.println("Failure!");
B
if (variable > 0)
if (variable < 50)
System.out.println("Success!");
else
System.out.println("Failure!");
C
if (variable > 0 && variable < 50)
System.out.println("Success!");
else
System.out.println("Failure!");
D
if (variable < 50)
if (variable > 0)
System.out.println("Success!");
else
System.out.println("Failure!");
E

C and D above

Response was: E
Wrong Incorrect (0 mark)
Check the code with the values -10, 10 and 70
Question 18 (1 mark) Attempt 1
If A has a value of 15, what will be the output of the following code:
if (A < 10)
System.out.println("I'm in the first section");
else if (A >= 15)
System.out.println("I'm in the second section");
else
System.out.println("I'm in the third section");

A
B
C
D

Nothing
I'm in the third section
I'm in the first section
I'm in the second section

Response was: D
Correct Correct (1 mark)
Question 19 (1 mark) Attempt 1
If A has a value of 15, what will be the output of the following code:
if (A > 10)
System.out.println("I'm in the first section");
else if (A < 15)
System.out.println("I'm in the second section");
else if (A == 12)
System.out.println("I'm in the third section");
A
B
C
D

I'm in the third section


I'm in the first section
I'm in the second section
Nothing

Response was: C
Wrong Incorrect (0 mark)
Trace the code with pencil and paper. Review Section 4.3 of the notes
Question 20 (1 mark) Attempt 1
In the following switch statement, the selector month has been declared an int:
switch (month) {
case 1 :
case 2 :
case 3 : System.out.println("First Quarter");
case 4 :
case 5 :
case 6 : System.out.println("Second Quarter");
break;
case 7 :
case 8 :
case 9 : System.out.println("Third Quarter");
break;
case 10 :
case 11 :
case 12 : System.out.println("Fourth Quarter");
break;
default :
System.out.println("invalid month number");
}
What will happen if the month number is 2?
A
the segment print "invalid month number" as no action has been s
pecified for the selector value '2'
B
the segement will print "First Quarter", "Second Quarter", "Thir
d Quarter", "Fourth Quarter" (on separate lines)

C
the segment will print "First Quarter" only
D
the segment will print "First Quarter" and "Second Quarter" (on
separate lines)
Response was: A
Wrong Incorrect (0 mark)

S-ar putea să vă placă și