Exam Questions and CORRECT Answers
Which of the following are valid Java Identifiers? Choose all that apply. - CORRECT
ANSWER - age1
a555c
SpEcIaL_vAlUe
Tax
What will be the output of this code?
int x = 2;
int y = 5;
x = y + 1;
y = x - 1;
x = x + 1;
y = y - 1;
x = x - y;
System.out.print(x); - CORRECT ANSWER - 3
Given the following int (integer) variables, a = 5, b = 5, c = 45, d = 6, evaluate the expression:
a * b - c / d - CORRECT ANSWER - 17
Evaluate this logical expression:
false && true - CORRECT ANSWER - False
Evaluate this expression: 1 < 3 - CORRECT ANSWER - True
Evaluate this expression:
,3 + 1 >= 4 || 19 - 3 < 8 - CORRECT ANSWER - True
Which of the following are Java primitive data types? Choose all that apply. - CORRECT
ANSWER - float
boolean
char
double
Which of the following Java literals have the data type float? Choose all that apply. - CORRECT
ANSWER - 123f
-3f
When the following expression is evaluated, the result will be what Java data type?
97f / 53 - CORRECT ANSWER - float
Which of the following would be the best data type for a variable to store a count of the number
of people currently living in the United States? - CORRECT ANSWER - int
Write a line of Java code that will declare a char variable named formthat is initialized to the
value 'y'. - CORRECT ANSWER - char form = 'y';
What will this small program output?
class Main {
public static void foo() {
int x=9;
System.out.println(x);
}
public static int x = 16;
public static void main(String[]args) {
,int x = 23;
foo();
}
} - CORRECT ANSWER - 9
What is the output of this Java program?
class Driver {
public static void main(String[]args) {
foo(6);
bar(5);
}
static void foo(int a) {
System.out.print(a);
}
static void bar(int a) {
foo(a + 1);
System.out.print(a);
}
} - CORRECT ANSWER - 665
What is the output of this Java program?
class Driver {
public static void main(String[] args) {
int a = foo(4);
int b = bar(3);
}
static int foo(int a) {
a = bar(a+4);
, System.out.print(a);
return a;
}
static int bar(int a) {
System.out.print(a);
return a - 1;
}
} - CORRECT ANSWER - 873
What is the output of this Java program?
class Driver {
public static void main(String[] args) {
int a = 8;
int b = 6;
int c = 6;
int x = 1;
if (a < 3) {
x = x + 800;
}
if (b < 6) {
x = x + 60;
}
if (c < 6) {
x = x + 6;
}
System.out.print(x);
}
} - CORRECT ANSWER - 1