0% found this document useful (0 votes)
2K views36 pages

1

1. The value assigned to x is the result of the expression -5*4/2 - 10 + 4, which is 7. 2. A byte has 8 bits. 3. The operators + and - are mathematical operators.

Uploaded by

Nindi nindong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views36 pages

1

1. The value assigned to x is the result of the expression -5*4/2 - 10 + 4, which is 7. 2. A byte has 8 bits. 3. The operators + and - are mathematical operators.

Uploaded by

Nindi nindong
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 36

1.

What
value is Mark for Review
assigned (1) Points
to x?

int x = 25
-5*4/
2 - 10 +
4;

9 (*)

34

Incorrect. Refer to Section 3 Lesson 2.

2. How many bits are in a byte?


Mark for Review
(1) Points

8 (*)

Correct

3. Which two are mathematical operators?


Mark for Review
(1) Points

(Choose all correct answers)

+ (*)

– (*)

Correct

4. Which data type is most commonly used to represent numeric data?


Mark for Review
(1) Points

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

(Choose all correct answers)

x = x +1; (*)

x = +1;

x+;

x++; (*)

x += 1; (*)

Incorrect. Refer to Section 3 Lesson 2.


6. This
declaration Mark for Review
represents a (1) Points
long data
type.
long a =
123L;

True (*)

False

Correct

7. What is the output? public static void main(String args[]) {


int x = 100; Mark for Review
int y = x; (1) Points
y++;
System.out.println("Value of x is " + x);
System.out.println("Value of y is " + y);
}

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

–27 to 27–1 (*)

–215 to 215–1

–231 to 231–1

–263 to 263–1

Correct

9. Identify the variable declared in the given code.


Mark for Review
public class Welcome { (1) Points
public static void main(String args[]) {
int a = 2;
System.out.println("a is " + a);
}
}

int

Welcome

a (*)

Incorrect. Refer to Section 3 Lesson 1.

10. What is the output?


Mark for Review
public class Hello { (1) Points
public static void main(String args[]) {
String str = ”Hello”;
str = ”World”;
System.out.println(str);
}
}

Hello
World
World (*)

Hello

Hello World

Incorrect. Refer to Section 3 Lesson 1.


11. Which
two Mark for Review
are (1) Points
valid?

(Choose all correct answers)


double doubleVar1 = 3.1; double doubleVar2 = 3.1; (*)

double doubleVar1, doubleVar2 = 3.1; (*)

double doubleVar1; doubleVar2 = 3.1.

double doubleVar1, double doubleVar2 = 3.1;

Correct

12. Which two are valid assignments of a?


Mark for Review
(1) Points

(Choose all correct answers)

int a = 10

int a = 10; (*)

int a = “10”;

int a; a = 10; (*)

Incorrect. Refer to Section 3 Lesson 1.

13. Which of the following two statements are true about variables?
Mark for Review
(1) Points

(Choose all correct answers)

The value assigned to a variable may never change.

They make code more flexible. (*)

Variables will be ignored by compiler.

The allow code to be edited more efficiently. (*)

Correct

14. Assigning a value to the variable is called “initialization”.


Mark for Review
(1) Points

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)
}
}

(Choose all correct answers)

strVal (*)

StringAssuming x is an int, which of the following are ways to increment


the value of x by 1?
Hello

intVal (*)

int

Incorrect. Refer to Section 3 Lesson 1.


Which two are
recommended Mark for Review
practices for (1) Points
naming final
variables?

(Choose all correct answers)

Capitalize every letter (*)

Separate words with an underscore (*)

Capitalize first letter

Separate words with an space

Incorrect. Refer to Section 3 Lesson 2.

2. What is the range of the byte data type?


Mark for Review
(1) Points

–27 to 27–1 (*)

–215 to 215–1

–231 to 231–1
–263 to 263–1

Correct

3. This declaration represents a long data type.


long a = 123L; Mark for Review
(1) Points

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

(Choose all correct answers)

x = x +1; (*)

x = +1;

x+;

x++; (*)

x += 1; (*)

Correct

5. Which data type is most commonly used to


represent numeric data? Mark for Review
(1) Points

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

Incorrect. Refer to Section 3


Lesson 2.

7. Which two are mathematical


operators? Mark for Review
(1) Points

(Choose all correct answers)

+ (*)

– (*)

Correct

8. What value is assigned to x?


Mark for Review
int x = 25 - 5 * 4 / 2 - 10 + 4; (1) Points

9 (*)

34

Incorrect. Refer to Section 3


Lesson 2.

9. Which of the following two


statements are true about Mark for Review
variables? (1) Points

(Choose all correct answers)

Variables will be ignored by


compiler.
The allow code to be edited
more efficiently. (*)
The value assigned to a
variable may never change.
They make code more flexible.
(*)

Correct

10. What is the output?


Mark for Review
public class Hello { (1) Points
public static void main(String
args[]) {
String str = ”Hello”;
str = ”World”;
System.out.println(str);
}
}

World (*)

Hello World

Hello
World
Hello

Incorrect. Refer to Section 3


Lesson 1.
11. Identify the variable
declared in the given Mark for Review
code. (1) Points

public class Welcome {


public static void
main(String args[]) {
int a = 2;
System.out.println("a
is " + a);
}
}

int

Welcome

a (*)

Incorrect. Refer to Section 3


Lesson 1.

12. Java is a strongly typed language; therefore you must


declare a data type for all variables. Mark for Review
(1) Points

True (*)

False

Correct

13. Which is valid syntax to declare and initialize a String


variable? Mark for Review
(1) Points

String x= “Java”; (*)


String x = Java;
String “x” = “Java”;

String “x” = Java;

Incorrect. Refer to Section 3


Lesson 1.

14. Which two are valid assignments of a?


Mark for Review
(1) Points

(Choose all correct answers)

int a = 10

int a = “10”;

int a; a = 10; (*)

int a = 10; (*)

Incorrect. Refer to Section 3


Lesson 1.

15. Assigning a value to the variable is called “initialization”.


Mark for Review
(1) Points

True (*)

False

Correct
1. Which two
statements Mark for Review
are true (1) Points
about the
Scanner
class?

(Choose all correct answers)

Scanners cannot read text files.

A Scanner’s delimiter can be changed. (*)

A Scanner object doesn’t have fields and methods.

A Scanner object opens a stream for collecting input. (*)

Correct

2. You write a statement that assigns a value to a String variable as shown


below. Mark for Review
(1) Points
String input = ”This is Java Program”;

This way of assigning values to variables is known as hard-coding.


True (*)

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

5. Which is a valid way to parse a String as an int?


Mark for Review
(1) Points

nt intVar1 = (int)"100";

int intVar1 = Integer.parseInt("One Hundred");

int intVar1 = "100";

int intVar1 = Integer.parseInt("100"); (*)

Incorrect. Refer to Section 3 Lesson 4.


1. void type
methods Mark for Review
don’t (1) Points
return
any
values

True (*)

False

Correct

2. Methods allow all instance of a class to share same behaviors.


Mark for Review
(1) Points
True (*)

False

Correct

3. Which is a valid way of calling the testMethod in the TestClass? Assume a


testInstance has been created. Mark for Review
(1) Points
public void testMethod(int x, double y){
System.out.println(x/y);
}

testInstance.testMethod(10);

testInstance.testMethod(3.5, 10);

testInstance.testMethod(10, 3.5); (*)

testInstance.testMethod(10, 3.5, 0);

testInstance.testMethod(3.5);

Incorrect. Refer to Section 4 Lesson 1.

4. Which of the following are the arguments in the following method?


Mark for Review
Employee emp = new Employee(); (1) Points
emp.calculateSalary(100000, 3.2, 15);

100000, 3.2, 15 (*)

emp.calculateSalary(100000, 3.2, 15);

emp

calculateSalary(100000, 3.2, 15);

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.

Methods can never be written with more than four parameters.

Methods can be written with any number of parameters. (*)

Methods cannot be written with parameters.

Parameter values can be used within the method code block. (*)

Incorrect. Refer to Section 4 Lesson 1.

7. Object instantiation is done using what keyword?


Mark for Review
(1) Points

new (*)

instance

void
System

Incorrect. Refer to Section 4 Lesson 1.

8. Which of the following two operations are appropriate for the main
method? Mark for Review
(1) Points

(Choose all correct answers)

Calling an instance object’s field and methods. (*)

Calling local variables declared within a class’s method

Assigning memory to the variables

Creating instances of objects (*)

Incorrect. Refer to Section 4 Lesson 1.

9. Which statement is true about packages?


Mark for Review
(1) Points

A package doesn’t contain a group of related classes.

Packages of the Java class library do not contain related classes.

A package makes it difficult to locate the related classes.

A package contains a group of related classes. (*)

Incorrect. Refer to Section 4 Lesson 2.


10. Which of the following wild card character is used to import all the classes
in a particular package? Mark for Review
(1) Points

* (*)

Incorrect. Refer to Section 4 Lesson 2.


11. Given the import
statement: Mark for Review
import (1) Points
java.awt.font.TextLayout;
which is the package
name?

java.awt

java.awt.font (*)
java

awt.font

Incorrect. Refer to Section 4


Lesson 2.

12. Import statements are placed above the class definition.


Mark for Review
(1) Points

True (*)

False

Correct

13. Which is a risk of using fully qualified class names when


importing? Mark for Review
(1) Points

The compiler runs longer.

Performance of the code is reduced.

Memory usage is increased.

Code readability is reduced. (*)

Incorrect. Refer to Section 4


Lesson 2.

14. Which two are valid import statements of the Scanner


class? Mark for Review
(1) Points
(Choose all correct answers)

import java.util.Scanner; (*)

import java.*;

import java.util.*; (*)

import java.util;

Incorrect. Refer to Section 4


Lesson 2.

15. Which package is implicitly imported?


Mark for Review
(1) Points

java.io

ava.awt

java.lang (*)

java.math

Incorrect. Refer to Section 4


Lesson 2.
1. The import statement
consists of two parts. Mark for Review
(1) Points
import
package.className;

One is the package


name and the other
is the classname.

True (*)

False

Correct

2. The classes of the Java class library are organized into


packages. Mark for Review
(1) Points

True (*)

False

Correct

3. Which two are valid import statements of the Scanner class?


Mark for Review
(1) Points
(Choose all correct answers)

import java.util.Scanner; (*)

import java.*;

import java.util.*; (*)

import java.util;

Correct

4. Which of the following wild card character is used to import all


the classes in a particular package? Mark for Review
(1) Points

* (*)

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

7. The JFrame and JOptionPane classes are in the javax.swing


package. Which two will import those classes? Mark for Review
(1) Points
(Choose all correct answers)

import javax.swing.J*;

import javax.swing.*; (*)

import javax.swing.JOptionPane;
import javax.swing.JFrame; (*)
import javax.swing;

Incorrect. Refer to Section 4


Lesson 2.

8. Once an object is instantiated, how might its fields and


methods be accessed in Java? Mark for Review
(1) Points

Using the colon(:) operator

Using the double-colon(::) operator

Using the comma(,) operator

Using the dot(.) operator (*)

Incorrect. Refer to Section 4


Lesson 1.

9. Methods allow all instance of a class to share same


behaviors. Mark for Review
(1) Points

True (*)

False

Correct

10. Which is a valid way of calling the testMethod in the


TestClass? Assume a testInstance has been created. Mark for Review
(1) Points
public void testMethod(int x, double y){
System.out.println(x/y);
}

testInstance.testMethod(3.5);

testInstance.testMethod(10, 3.5, 0);

testInstance.testMethod(10);

testInstance.testMethod(10, 3.5); (*)

testInstance.testMethod(3.5, 10);

Correct
11. Which of the following are
the arguments in the Mark for Review
following method? (1) Points

Employee emp = new


Employee();
emp.calculateSalary(100000,
3.2, 15);

emp.calculateSalary(100000, 3.2, 15);

100000, 3.2, 15 (*)

calculateSalary(100000, 3.2, 15);

emp

Correct

12. How many arguments does the following method


accept? Mark for Review
(1) Points
public void simpleInterest(double principal, int
noofYears, double interestRate){
System.out.println(“The interest rate is ”
+interestRate );
}

3 (*)

Incorrect. Refer to Section


4 Lesson 1.

13. Which of the following scenarios would be ideal for


writing a method? Mark for Review
(1) Points

For every five to six lines of code.

When you don’t find similar lines of code to


describe an object’s behavior.
When you don’t want to repeat similar lines of
code to describe an object’s behavior. (*)
To group similar data types together

Correct
14. In Java,
methods Mark for Review
usually (1) Points
hold the
properties
of an
object.
True

False (*)

Incorrect. Refer to Section 4 Lesson 1.

15. Object instantiation is done using what keyword?


Mark for Review
(1) Points

void

instance

new (*)

System

Incorrect. Refer to Section 4 Lesson 1.

1. What is the output?


Mark for Review
public static void main(String args[]) (1) Points
{
String alphaNumeric = "Java
World!" + 8;
System.out.println(alphaNumeric);
}

Java World!8 (*)

Java World! + 8

Java World! 8

Compilation error.

Incorrect. Refer to
Section 4 Lesson 3.

2. What is the output of the following code?


Mark for Review
public static void main(String args[]) { (1) Points
String firstString = "Java";
firstString = firstString.concat("World");
System.out.println(firstString);
}

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

4. The String concat() method concatenates only


String data types. Mark for Review
(1) Points

True (*)

False

Correct

5. The String class must be imported using


java.lang.String; Mark for Review
(1) Points

True

False (*)

Correct
6. String
objects are Mark for Review
immutable. (1) Points

True (*)

False

Correct

7. What is the output?


Mark for Review
public static void main(String args[]) { (1) Points
String greeting = "Java World!";
String w = greeting.substring(7, 11);
System.out.println(w);
}

rld! (*)

rld

orld!

ld!

Incorrect. Refer to Section 4 Lesson 3.


8. Using the Random class requires an import statement.
Mark for Review
(1) Points

True (*)

False

Correct

9. You need to generate random integer values between 0 and 80 (inclusive).


Which statement should you use? Mark for Review
(1) Points

nextInt(81); (*)

nextInt(80);

nextInt();

nextInt(0-79);

Incorrect. Refer to Section 4 Lesson 4.

10. Which class is used to generate random numbers?


Mark for Review
(1) Points

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

12. Every method of the Math class returns a numerical result.


Mark for Review
(1) Points

True (*)

False

Correct

13. What is the approximate value of PI?


Mark for Review
(1) Points

2.718

3.141 (*)

The value varies.

Incorrect. Refer to Section 4 Lesson 5.

14. Which two are the features of the Math class?


Mark for Review
(1) Points

(Choose all correct answers)

Math methods can be invoked with Strings as arguments.

The Math methods can be invoked without creating an instance of a


Math object. (*)
Common math functions like square root are taken care of in the
language. (*)
You don’t have to worry about the data type returned from a Math
method.

Incorrect. Refer to Section 4 Lesson 5.

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

2. Using the Random class requires an import statement.


Mark for
Review
(1) Points

True (*)

False

Correct

3. Which class is used to generate random numbers?


Mark for
Review
(1) Points

Random (*)

Number

Double

Integer

Correct

4. Which values are returned by the method nextBoolean();


Mark for
Review
(1) Points

Returns the next value.


An integer value.
Nothing is returned.

Either a true or false. (*)

Incorrect. Refer to Section 4 Lesson 4.

5. All the methods in the Math class are static methods.


Mark for
Review
(1) Points

True (*)

False

Incorrect. Refer to Section 4 Lesson 5.


6.What is the
package Mark for
name Review
which
(1) Points
contains
Math
class?

java.lang (*)

java.net

java.awt

java.io

Incorrect. Refer to Section 4 Lesson 5.

7. A constant field, like Math.PI is used to represent a fixed value.


Mark for
Review
(1) Points

True (*)

False

Correct

8. Which two are the features of the Math class?


Mark for
Review
(1) Points

(Choose all correct answers)

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

9. String objects are immutable.


Mark for
Review
(1) Points

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.

Incorrect. Refer to Section 4 Lesson 3.

10.What is the output?


Mark for
public static void main(String args[]) { Review
String greeting = "Java World!";
(1) Points
String w = greeting.replace("a", "A");
System.out.println(w);
}

JAva World!

Java World!

JavA World!

JAvA World! (*)

Incorrect. Refer to Section 4 Lesson 3.

11.A String
is a Mark for
sequenc Review
e
(1) Points
characte
rs.
True (*)

False

Correct

12. The replaceFirst() method


replaces only the first Mark for
occurrence of matching Review
character pattern in a string.
(1) Points

True (*)

False

Correct

13. Which method returns the


length of a String? Mark for
Review
(1) Points

compareTo()

length() (*)

findLength ()

charAt()

Correct

14. What is the output?


Mark for
public static void main(String Review
args[]) {
(1) Points
String alphaNumeric =
"Java World!" + 8;
System.out.println(alphaNu
meric);
}

Java World!8 (*)

Java World! 8

Java World! + 8

Compilation error.

Correct

15. What is the output?


Mark for
public static void main(String Review
args[]) {
(1) Points
String greeting = "Java
World!";
String w =
greeting.substring(7, 11);
System.out.println(w);
}

rld! (*)

ld!

rld

orld!

Incorre
ct.
Refer
to
Section
4
Lesson
3.
1.Which two
are not Mark for Review
logical (1) Points
operators?

(Choose all correct answers)

&&

||

% (*)

+ (*)

Incorrect. Refer to Section 5 Lesson 2.

2. In Java, an if statement can be nested inside another if statement.


Mark for Review
(1) Points

True (*)

False

Correct

3. A customer is eligible for a discount based on certain criteria. Under what


conditions does “You qualify for a discount” print? (Hint: There may be Mark for Review
more than one correct answer) (1) Points

int purchase;
int rewardPoints;
if (purchase >= 2000 || rewardPoints >= 4000) {
System.out.println("You qualify for discount");
}

(Choose all correct answers)

When rewardPoints is more than 1000 and purchase is 1000

When rewardPoints is more than 2000 or purchase greater than


1000
When purchase is 4000 and rewardPoints is 2000 (*)

When purchase is 2000 regardless of the value of rewardPoints (*)

Incorrect. Refer to Section 5 Lesson 2.

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

7. Which two statements are true about the default statement?


Mark for Review
(1) Points

(Choose all correct answers)


A default statement is required in every switch statement.

A default statement is executed by default when the program is


executed.
The default statement is optional in switch statement. (*)

When the input does not match any of the cases, the default
statement is executed. (*)

Incorrect. Refer to Section 5 Lesson 3.

8. What is the output?


Mark for Review
public static void main(String args[]) { (1) Points
char ch ='c';
switch(ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("Vowels");
break;
default:
System.out.println("Consonants");
}
}

Consonants (*)

Vowels

Vowels

Compilation error

Correct

9. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
int age = 43;
if (age == 43){
System.out.print("Bob is 43 ");
}
if (age == 50){
System.out.print("Bob is 50 ");
}
}

Bob is 50

Bob is 43 (*)

Bob is 43 Bob is 50

No output

Incorrect. Refer to Section 5 Lesson 1.


10. Which operator is used to test if both sides of a boolean expression are
equal? Mark for Review
(1) Points

<=

== (*)

>=

Incorrect. Refer to Section 5 Lesson 1.


6.A break
statement Mark for Review
causes (1) Points
control to
transfer to
the end of
the switch
statement.

True (*)

False

Correct

7. Which two statements are true about the default statement?


Mark for Review
(1) Points

(Choose all correct answers)

A default statement is required in every switch statement.

A default statement is executed by default when the program is


executed.
The default statement is optional in switch statement. (*)

When the input does not match any of the cases, the default
statement is executed. (*)

Incorrect. Refer to Section 5 Lesson 3.

8. What is the output?


Mark for Review
public static void main(String args[]) { (1) Points
char ch ='c';
switch(ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("Vowels");
break;
default:
System.out.println("Consonants");
}
}

Consonants (*)

Vowels

Vowels

Compilation error

Correct

9. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
int age = 43;
if (age == 43){
System.out.print("Bob is 43 ");
}
if (age == 50){
System.out.print("Bob is 50 ");
}
}

Bob is 50

Bob is 43 (*)

Bob is 43 Bob is 50

No output

Incorrect. Refer to Section 5 Lesson 1.

10. Which operator is used to test if both sides of a boolean expression are
equal? Mark for Review
(1) Points

<=

== (*)

>=

Incorrect. Refer to Section 5 Lesson 1.


6.A break
statement Mark for Review
causes (1) Points
control to
transfer to
the end of
the switch
statement.

True (*)
False
Correct

7. Which two statements are true about the default statement?


Mark for Review
(1) Points

(Choose all correct answers)

A default statement is required in every switch statement.

A default statement is executed by default when the program is


executed.
The default statement is optional in switch statement. (*)

When the input does not match any of the cases, the default
statement is executed. (*)

Incorrect. Refer to Section 5 Lesson 3.

8. What is the output?


Mark for Review
public static void main(String args[]) { (1) Points
char ch ='c';
switch(ch) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
System.out.println("Vowels");
break;
default:
System.out.println("Consonants");
}
}

Consonants (*)

Vowels

Vowels

Compilation error

Correct

9. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
int age = 43;
if (age == 43){
System.out.print("Bob is 43 ");
}
if (age == 50){
System.out.print("Bob is 50 ");
}
}
Bob is 50

Bob is 43 (*)

Bob is 43 Bob is 50

No output

Incorrect. Refer to Section 5 Lesson 1.

10. Which operator is used to test if both sides of a boolean expression are
equal? Mark for Review
(1) Points

<=

== (*)

>=

Incorrect. Refer to Section 5 Lesson 1.


1.A String
comparison Mark for Review
with == (1) Points
compares the
Strings’
locations in
memory and
not the
content of the
String.

True (*)

False

Correct

2. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
int age = 43;
if (age == 43){
System.out.print("Bob is 43 ");
}
if (age == 50){
System.out.print("Bob is 50 ");
}
}

Bob is 50

Bob is 43 Bob is 50

No output

Bob is 43 (*)
Incorrect. Refer to Section 5 Lesson 1.

3. What is the output?


Mark for Review
public static void main(String[] args) { (1) Points
String name = "Java";
String language = "Programming";
String fullName = name + language;
boolean test = fullName.equals(name + language);
System.out.println(test);
}

True (*)

JavaProgramming

False

Java Programming

Incorrect. Refer to Section 5 Lesson 1.

4. Which are used in a boolean expression?


Mark for Review
(1) Points

(Choose all correct answers)

Errors

Loops

Operators (*)

Variables (*)

Incorrect. Refer to Section 5 Lesson 1.

5. What are the possible values of a boolean data type in Java?


Mark for Review
(1) Points

good/bad

true/false (*)

yes/no

0/1

Incorrect. Refer to Section 5 Lesson 1.


6.Which three
are Mark for Review
conditional (1) Points
statements?

(Choose all correct answers)


switch statement (*)

if statement (*)

for loop

do while loop

if/else statement (*)

Correct

7. The equal sign (=) is used to make an assignment, whereas the ==


sign merely makes a comparison and returns a boolean. Mark for Review
(1) Points

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 false

If the first condition is false, but the second condition is true

If the first condition is true, but the second condition is false

If both the first condition and second condition are true (*)

Incorrect. Refer to Section 5 Lesson 2.

10. Which two are not logical operators?


Mark for Review
(1) Points

(Choose all correct answers)

||
&&

!
% (*)

+ (*)

Correct
6.Which three
are Mark for Review
conditional (1) Points
statements?

(Choose all correct answers)

switch statement (*)

if statement (*)

for loop

do while loop

if/else statement (*)

Correct

7. The equal sign (=) is used to make an assignment, whereas the ==


sign merely makes a comparison and returns a boolean. Mark for Review
(1) Points

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 false

If the first condition is false, but the second condition is true

If the first condition is true, but the second condition is false

If both the first condition and second condition are true (*)
Incorrect. Refer to Section 5 Lesson 2.

10. Which two are not logical operators?


Mark for Review
(1) Points

(Choose all correct answers)

||

&&

% (*)

+ (*)

Correct
Which two of the following data types can be used in a switch statement?

You might also like