JAVA EXAM QUESTIONS WITH ALL
CORRECT ANSWERS
If you declare a variable as an instance variable within a class and you declare and use
the same variable name within a method of the class, then within the method - Answer-
The variable used inside the method takes precedence
A method variable ____ a class variable within the same name - Answer-Override
Non-ambiguous, overloaded methods must have the same - Answer-Name
If a method is written to receive a double parameter, and you assign an integer to the
method, then the method will - Answer-Work correctly, the integer will be promoted to a
double
A constructor ____ parameters - Answer-Can receive
A constructor ____ overloaded - Answer-Can be
If a class is named Student, the class constructors named is - Answer-Student
If you use the automatically supplied default constructor when you create an object -
Answer-Numeric fields are set to 0 (zero)
The code between a pair of curly braces in a method is a - Answer-Block
When a block exists within another block, the blocks are - Answer-Nested
The logical structure in which one instruction occurs after another with no branching is a
- Answer-Sequence
Which of the following is typically used in a flowchart to indicate a decision? - Answer-
Diamond
Which of the following is not a type of it statement? - Answer-Reserve if
A decision is based on a(n) ____ value - Answer-Boolean
, In Java, the value of (4 > 7) is ____. - Answer-False
Assuming the variable q has been assigned the value 3, which of the following
statements displays XXX? - Answer-if ( q >7);
System.out.println("XXX");
What is the output of the following code segment?
t = 10
if ( t > 7)
System.out.print("AAA");
System.out.print("BBB"); - Answer-AAA
What is the output of the following code segment?
t=7
if (t > 7)
System.out.print("AAA");
System.out.print("BBB"); - Answer-BBB
When you code an if statement within another if statement, as in the following then the if
statements are ____.
if (a > b)
if (c > d) x = 0; - Answer-Nested
The operator that combines two conditions into a single Boolean value that is true only
when both of the conditions are true, but is false other wise, is ____. - Answer-&&
The operator that combines two conditions into a single Boolean value that is true when
at least one of the conditions is true is ____. - Answer-||
Which of the following groups has the lowest operator precedence? - Answer-Logical
OR
Which of the following displays "Error" when a student ID is less than 1000 or more than
9999? - Answer-if (stuID < 1000 )
System.out.println("Error");
else
if (stuID > 9999)
System.out.println("Error");
You can use the statement to terminate a switch structure - Answer-break
The argument testing in a switch structure can be any of the following except a(n) ____.
- Answer-double
Assuming a variable w has been assigned to the value 15, what does the following
statement do?
CORRECT ANSWERS
If you declare a variable as an instance variable within a class and you declare and use
the same variable name within a method of the class, then within the method - Answer-
The variable used inside the method takes precedence
A method variable ____ a class variable within the same name - Answer-Override
Non-ambiguous, overloaded methods must have the same - Answer-Name
If a method is written to receive a double parameter, and you assign an integer to the
method, then the method will - Answer-Work correctly, the integer will be promoted to a
double
A constructor ____ parameters - Answer-Can receive
A constructor ____ overloaded - Answer-Can be
If a class is named Student, the class constructors named is - Answer-Student
If you use the automatically supplied default constructor when you create an object -
Answer-Numeric fields are set to 0 (zero)
The code between a pair of curly braces in a method is a - Answer-Block
When a block exists within another block, the blocks are - Answer-Nested
The logical structure in which one instruction occurs after another with no branching is a
- Answer-Sequence
Which of the following is typically used in a flowchart to indicate a decision? - Answer-
Diamond
Which of the following is not a type of it statement? - Answer-Reserve if
A decision is based on a(n) ____ value - Answer-Boolean
, In Java, the value of (4 > 7) is ____. - Answer-False
Assuming the variable q has been assigned the value 3, which of the following
statements displays XXX? - Answer-if ( q >7);
System.out.println("XXX");
What is the output of the following code segment?
t = 10
if ( t > 7)
System.out.print("AAA");
System.out.print("BBB"); - Answer-AAA
What is the output of the following code segment?
t=7
if (t > 7)
System.out.print("AAA");
System.out.print("BBB"); - Answer-BBB
When you code an if statement within another if statement, as in the following then the if
statements are ____.
if (a > b)
if (c > d) x = 0; - Answer-Nested
The operator that combines two conditions into a single Boolean value that is true only
when both of the conditions are true, but is false other wise, is ____. - Answer-&&
The operator that combines two conditions into a single Boolean value that is true when
at least one of the conditions is true is ____. - Answer-||
Which of the following groups has the lowest operator precedence? - Answer-Logical
OR
Which of the following displays "Error" when a student ID is less than 1000 or more than
9999? - Answer-if (stuID < 1000 )
System.out.println("Error");
else
if (stuID > 9999)
System.out.println("Error");
You can use the statement to terminate a switch structure - Answer-break
The argument testing in a switch structure can be any of the following except a(n) ____.
- Answer-double
Assuming a variable w has been assigned to the value 15, what does the following
statement do?