1
1
What
value is Mark for Review
assigned (1) Points
to x?
int x = 25
-5*4/
2 - 10 +
4;
9 (*)
34
8 (*)
Correct
+ (*)
– (*)
Correct
int (*)
float
String
short
Correct
5. Assuming x is an int, which of the following are ways to increment the value
of x by 1? Mark for Review
(1) Points
x = x +1; (*)
x = +1;
x+;
x++; (*)
x += 1; (*)
True (*)
False
Correct
Value of x is 0
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 1
Value of x is 100
Value of y is 101 (*)
Correct
8. What is the range of the byte data type?
Mark for Review
(1) Points
–215 to 215–1
–231 to 231–1
–263 to 263–1
Correct
int
Welcome
a (*)
Hello
World
World (*)
Hello
Hello World
Correct
int a = 10
int a = “10”;
13. Which of the following two statements are true about variables?
Mark for Review
(1) Points
Correct
True (*)
False
Correct
15. Identify the names of two variables used in the given code.
Mark for Review
public class Variables { (1) Points
public static void main(String args[]) {
String strVal = "Hello";
int intVal = 0;
System.out.println("Integer: " +intVal)
}
}
strVal (*)
intVal (*)
int
–215 to 215–1
–231 to 231–1
–263 to 263–1
Correct
True (*)
False
Correct
4. Assuming x is an int, which of the following are
ways to increment the value of x by 1? Mark for Review
(1) Points
x = x +1; (*)
x = +1;
x+;
x++; (*)
x += 1; (*)
Correct
int (*)
float
String
short
Correct
What is the output?
Mark for Review
public class Person { (1) Points
public static void
main(String args[]) {
int age = 20;
System.out.println("Value
of age: " +age);
age = 5 + 3;
System.out.println("Value
of age: " +age);
age = age + 1;
age++;
System.out.println("Value
of age: " +age);
}
}
Value of age: 20
Value of age: 8
Value of age: 10 (*)
Value of age: 20
Value of age: 28
Value of age: 38
Value of age: 20
Value of age: 208
Value of age: 20810
Value of age: 20
Value of age: 8
Value of age: 9
+ (*)
– (*)
Correct
9 (*)
34
Correct
World (*)
Hello World
Hello
World
Hello
int
Welcome
a (*)
True (*)
False
Correct
int a = 10
int a = “10”;
True (*)
False
Correct
1. Which two
statements Mark for Review
are true (1) Points
about the
Scanner
class?
Correct
False
Correct
3. The Scanner class considers space as the default delimiter while reading
the input. Mark for Review
(1) Points
True (*)
False
Correct
4. The Java compiler automatically promotes byte, short, and chars data
type values to int data type. Mark for Review
(1) Points
True (*)
False
Correct
nt intVar1 = (int)"100";
True (*)
False
Correct
False
Correct
testInstance.testMethod(10);
testInstance.testMethod(3.5, 10);
testInstance.testMethod(3.5);
emp
Correct
5. In Java,
methods Mark for Review
usually (1) Points
hold the
properties
of an
object.
True
False (*)
Correct
6. Which of
the Mark for Review
following (1) Points
statements
are true?
(Choose all correct answers)
Parameter values can never be used within the method code block.
Parameter values can be used within the method code block. (*)
new (*)
instance
void
System
8. Which of the following two operations are appropriate for the main
method? Mark for Review
(1) Points
* (*)
java.awt
java.awt.font (*)
java
awt.font
True (*)
False
Correct
import java.*;
import java.util;
java.io
ava.awt
java.lang (*)
java.math
True (*)
False
Correct
True (*)
False
Correct
import java.*;
import java.util;
Correct
* (*)
Correct
5. Which
package is Mark for Review
implicitly (1) Points
imported?
ava.awt
java.math
java.lang (*)
java.io
Correct
6. Given the import
statement: Mark for Review
import (1) Points
java.awt.font.TextLayout;
which is the package
name?
java.awt
java
java.awt.font (*)
awt.font
Correct
import javax.swing.J*;
import javax.swing.JOptionPane;
import javax.swing.JFrame; (*)
import javax.swing;
True (*)
False
Correct
testInstance.testMethod(3.5);
testInstance.testMethod(10);
testInstance.testMethod(3.5, 10);
Correct
11. Which of the following are
the arguments in the Mark for Review
following method? (1) Points
emp
Correct
3 (*)
Correct
14. In Java,
methods Mark for Review
usually (1) Points
hold the
properties
of an
object.
True
False (*)
void
instance
new (*)
System
Java World! + 8
Java World! 8
Compilation error.
Incorrect. Refer to
Section 4 Lesson 3.
Java
Java World
World
JavaWorld (*)
Incorrect. Refer to
Section 4 Lesson 3.
3. The replaceFirst() method replaces only the first
occurrence of matching character pattern in a Mark for Review
string. (1) Points
True (*)
False
Correct
True (*)
False
Correct
True
False (*)
Correct
6. String
objects are Mark for Review
immutable. (1) Points
True (*)
False
Correct
rld! (*)
rld
orld!
ld!
True (*)
False
Correct
nextInt(81); (*)
nextInt(80);
nextInt();
nextInt(0-79);
Random (*)
Integer
Number
Double
Correct
11. You need
to generate Mark for Review
random (1) Points
integer
values in
the range 2
through 10.
This code
fragment
will
produce
the desired
result.
Random r
= new
Random();
r.nextInt(9)
+ 2;
True (*)
False
Correct
True (*)
False
Correct
2.718
3.141 (*)
15. The Math class methods can be called without creating an instance of a
Math object. Mark for Review
(1) Points
True (*)
False
Correct
1.You need to
generate Mark for
random Review
integer values
(1) Points
in the range 2
through 10.
This code
fragment will
produce the
desired result.
Random r =
new
Random();
r.nextInt(9) +
2;
True (*)
False
Correct
True (*)
False
Correct
Random (*)
Number
Double
Integer
Correct
True (*)
False
java.lang (*)
java.net
java.awt
java.io
True (*)
False
Correct
Common math functions like square root are taken care of in the language.
(*)
Math methods can be invoked with Strings as arguments.
You don’t have to worry about the data type returned from a Math
method.
The Math methods can be invoked without creating an instance of a Math
object. (*)
Correct
True (*)
You False
need to
generat
e
random
integer
values
in the
range 2
throug
h 10.
This
code
fragme
nt will
produc
e the
desired
result.
JAva World!
Java World!
JavA World!
11.A String
is a Mark for
sequenc Review
e
(1) Points
characte
rs.
True (*)
False
Correct
True (*)
False
Correct
compareTo()
length() (*)
findLength ()
charAt()
Correct
Java World! 8
Java World! + 8
Compilation error.
Correct
rld! (*)
ld!
rld
orld!
Incorre
ct.
Refer
to
Section
4
Lesson
3.
1.Which two
are not Mark for Review
logical (1) Points
operators?
&&
||
% (*)
+ (*)
True (*)
False
Correct
int purchase;
int rewardPoints;
if (purchase >= 2000 || rewardPoints >= 4000) {
System.out.println("You qualify for discount");
}
4. In the AND (&&) test, if the first expression on the left hand side is false,
then there is no need to evaluate the second statement. Mark for Review
(1) Points
True (*)
False
Correct
5. The switch statement is a more efficient way to write code when dealing
with a large range of unknown values. Mark for Review
(1) Points
True
False (*)
Correct
6.A break
statement Mark for Review
causes (1) Points
control to
transfer to
the end of
the switch
statement.
True (*)
False
Correct
When the input does not match any of the cases, the default
statement is executed. (*)
Consonants (*)
Vowels
Vowels
Compilation error
Correct
Bob is 50
Bob is 43 (*)
Bob is 43 Bob is 50
No output
<=
== (*)
>=
True (*)
False
Correct
When the input does not match any of the cases, the default
statement is executed. (*)
Consonants (*)
Vowels
Vowels
Compilation error
Correct
Bob is 50
Bob is 43 (*)
Bob is 43 Bob is 50
No output
10. Which operator is used to test if both sides of a boolean expression are
equal? Mark for Review
(1) Points
<=
== (*)
>=
True (*)
False
Correct
When the input does not match any of the cases, the default
statement is executed. (*)
Consonants (*)
Vowels
Vowels
Compilation error
Correct
Bob is 43 (*)
Bob is 43 Bob is 50
No output
10. Which operator is used to test if both sides of a boolean expression are
equal? Mark for Review
(1) Points
<=
== (*)
>=
True (*)
False
Correct
Bob is 50
Bob is 43 Bob is 50
No output
Bob is 43 (*)
Incorrect. Refer to Section 5 Lesson 1.
True (*)
JavaProgramming
False
Java Programming
Errors
Loops
Operators (*)
Variables (*)
good/bad
true/false (*)
yes/no
0/1
if statement (*)
for loop
do while loop
Correct
True (*)
False
Correct
8. In the AND (&&) test, if the first expression on the left hand side is
false, then there is no need to evaluate the second statement. Mark for Review
(1) Points
True (*)
False
Correct
9. In a boolean expression which uses the && operator, what would make
this expression evaluate to true? Mark for Review
(1) Points
boolean x = (firstCondition && secondCondition);
If both the first condition and second condition are true (*)
||
&&
!
% (*)
+ (*)
Correct
6.Which three
are Mark for Review
conditional (1) Points
statements?
if statement (*)
for loop
do while loop
Correct
True (*)
False
Correct
8. In the AND (&&) test, if the first expression on the left hand side is
false, then there is no need to evaluate the second statement. Mark for Review
(1) Points
True (*)
False
Correct
9. In a boolean expression which uses the && operator, what would make
this expression evaluate to true? Mark for Review
(1) Points
boolean x = (firstCondition && secondCondition);
If both the first condition and second condition are true (*)
Incorrect. Refer to Section 5 Lesson 2.
||
&&
% (*)
+ (*)
Correct
Which two of the following data types can be used in a switch statement?