WorksheetsJava Basics
Total questions: 22
Worksheet time: 17mins
Which of the following statements about Java's primitive data types is false?
Java defines eight primitive types, also referred to as simple types
The int type is a signed 32-bit type
The char type is a 16-bit Unicode type with a range of 0 to 65,536
A boolean value can be implicitly converted to an integer (0 or 1) for use in arithmetic expressions
What will be the output of the following code snippet: System.out.println(10 + 20 + "30");?
600
10 20 30
102030
3030
Which of the following is true regarding numeric literals?
An integer literal, by default, is of type long
Underscores can be embedded in numeric literals (e.g., 9_423_497_862.0) to improve readability, and they are discarded by the compiler
A floating-point literal, by default, is of type float
Character literals are enclosed in double quotes
Which statement correctly describes the declaration and initialization of variables in Java?
Variables can only be initialized with values that are already known at compile time
All variables must be initialized at the time of their declaration
A variable is defined by an identifier, a type, and an optional initializer
Arrays in Java must always be one-dimensional
Java's bitwise operators can be applied to which of the following data types?
float and double only
Integer types: long, int, short, char, and byte
boolean only
All primitive types except boolean
What is the outcome of a relational operator in Java?
An integer value indicating the relationship (e.g., 0 for equality, 1 for greater than)
A string describing the relationship
A boolean value (true or false)
All primitive types except boolean
Consider the following Java code snippet: int result = (value > 10) ? 100 : 50; What does result hold if value is 7?
100
true
false
50
To change the default order of evaluation in an expression, such as forcing an addition to occur before multiplication, which lexical element should be used
Commas
Semicolons
Parentheses
Square brackets
Which of the following describes a limitation of Java's switch statement compared to the if statement?
The switch statement can evaluate any type of Boolean expression, while if is restricted to equality tests
The switch statement can only test for equality between the expression's value and its case constants
The if statement does not support else clauses, whereas switch does
switch statements are generally less efficient than a set of nested if statements
What is a characteristic of the do-while loop in Java?
The loop's condition is evaluated before the body of the loop is executed for the first time
It is primarily used for iterating over collections and arrays (the "for-each" style)
The body of the loop is executed at least once, regardless of the initial condition
It can only be controlled by an integer counter
In Java, which statement is used to terminate the execution of the current loop (e.g., for, while, do-while) or switch statement and transfer control to the statement immediately following the loop or switch?
continue
return
throw
break
Predict the output
21
23
24
24.33
Predict the Ouput
a2
c
99
Error
Condition met.
Condition not met.
true
Error
Predcit the output
1 2 3 4
1 2 3
1 2 3 4 5
No Output
5 6
5 6
5 6 5 6
Compilation Error
5 6
Predict the output
1 2 3
2 2 4
224
2 4 4
Predict the output
1 3 4
1 2 3 4
1 2 3
1 3 4 5
Predict the output
One
One Two
One Two Default
Error
Predict the output
Hi
Hi
HI
Hi
No Output
Error
Predict The Output
0 1 2
1 2 3
1 2 3 4
0 1 2 3
Predict the Output
A
B
Error
No Output
