correct marked answers Wilfrid Laurier University
CP213 – QUIZ 1
Java differentiates between how many types of variables?
a) 4, instance, static, local, and parameter variable
b) 3, instance, local and parameter variable
c) 2, instance, static, and local variables
d) Supports only instance variable
If the following code snippet is executed, what will be the output?
public void test3()
{
int i = 50000;
short s = i;
}
a) s will be 50000
b) s will be between -32787 and 32786
c) s will be between -128 to 127
d) The program does not compile.
When the following code snippet is executed, what will be the output?
public void test() {
int input = 7;
int output = ++input + ++input + ++input;
System.out.println(output);
}
a) -20
b) 109
c) 27
d) 35
e) Compilation Error or Runtime Error
When the following code snippet is executed, what will be the output?
public static void test5() {
int i = 4;
int j = 21;
int k = ++i * 7 + 2 - j--;
System.out.println("k = " + k);
}
a) k = 16
b) The program does not compile.
c) k = 11
d) k = 17
In Java static variable is used to
a) refer to common properties to all objects.
b) get a persistent value between different method calls.
c) It gets memory only once in a class area at the time of class loading.
1
, d) All are correct.
2