WorksheetsG10 | Java - Unit Test 01
Total questions: 20
Worksheet time: 20mins
What is the keyword used to declare a variable in Java?
variable
declare
int
string
What is the default value of an int variable in Java?
10
1
0
null
What is the purpose of the 'if' statement in Java?
To make decisions in the code based on certain conditions
To create a loop
To declare a new variable
To print a message to the console
What is the difference between '==' and 'equals()' in Java?
== operator compares the values of two objects, while equals() method compares the contents of two objects.
equals() operator compares the values of two objects, while == method compares the contents of two objects.
equals() method is used for primitive data types, while == operator is used for objects.
equals() method compares the references of two objects, while == operator compares the contents of two objects.
How do you declare an array in Java?
arrayName type[];
arrayName[] type;
type[] arrayName;
arrayName type[] = new arrayName[];
What is the purpose of the 'while' loop in Java?
To execute the code when a specified condition is false
To execute the code based on a random condition
To execute the code only once
To repeatedly execute a block of code as long as a specified condition is true.
What is the difference between 'do-while' and 'while' loop in Java?
The 'while' loop will always execute the code block at least once
The 'do-while' loop is not supported in Java
The 'do-while' loop will always execute the code block at least once.
The 'do-while' loop can only be used for finite iterations
What is the scope of a local variable in Java?
Limited to the block in which it is declared
Limited to the method in which it is declared
Limited to the class in which it is declared
Accessible throughout the entire program
What is the purpose of the 'switch' statement in Java?
To select one of many code blocks to be executed.
To randomly select a code block to be executed
To execute all code blocks simultaneously
To make the code more confusing
How do you access the last element of an array in Java?
arrayName[last]
arrayName[arrayName.length - 1]
arrayName[-1]
arrayName[arrayName.length]
A while loop carries on as long as...
The condition in the brackets is true
The condition in the brackets is false
i < 10
the for loop has not ended
A while loop has the following format:
while (condition)
{
...
}
while
{
...
}
continue while (condition)
{
...
}
while [condition]
[
...;
]
Which modifiers makes a method accessible without creating an object of the class?
static
public
How do you insert COMMENTS in Java code?
# This is a comment
/* This is a comment
// This is a comment
Which data type is used to create a variable that should store text?
myString
String
Txt
string
What is the main difference between float and double data types?
4.1 is an example of float.
4.11 is an example of double.
Float consists of 8 bytes, and double consists of 4 bytes.
Float consists of 4 bytes, and double consists of 8 bytes.
a = {0, 2, 3, 4} and v = 2?
a = {0, 2, 3, 4} and v = 1?
Find the output of the following snippet.
class Numbers
{
public static void main(String args[])
{
int a=20, b=10;
if((a<b)&&(b++ <25))
{
System.out.println("this is any language logic");
}
System.out.println(b);
}
}
10
12
11
Compilation Error
Java is named after a type of coffee.
TRUE
FALSE
