Font size
WorksheetsCore Java Concepts Quiz (1)
Total questions: 48
Worksheet time: 25mins
Which of the following is a primitive data type in Java?
String
class
int
Object
Which data type is used to store true or false values?
char
boolean
double
byte
What is the purpose of declaring a variable in Java?
To define a class.
To allocate memory to store data.
To create a new method.
To print output to the console.
Which operator is used for equality comparison in Java?
=
==
!=
>
What is the result of the expression 5 % 2?
2.5
1
0
7
Which of the following is a logical AND operator in Java?
|
&
||
&&
Which keyword is used to start an if statement in Java?
when
if
condition
check
Which loop in Java guarantees that the code block will execute at least once?
for loop
while loop
do-while loop
if-else statement
What is the purpose of the break statement within a loop?
To skip the current iteration and continue to the next.
To terminate the loop immediately.
To execute the loop in reverse order.
To define the loop's condition.
How do you declare an array of integers named numbers that can hold 5 elements?
int numbers = new array[5];
array numbers = new int(5);
int[] numbers = new int[5];
int numbers[5] = new int[];
What is the index of the first element in an array in Java?
1
0
The size of the array
-1
How do you access the element at index 2 in an array named data?
data(2)
data[2]
data.get(2)
data.element(2)
What is a class in Java?
An instance of an object.
A blueprint for creating objects.
A primitive data type.
A method that belongs to an object.
What is an object in Java?
A definition of attributes and behaviors.
A keyword used to define a class.
An instance of a class.
A collection of related classes.
What is encapsulation in OOP?
The ability of an object to take on many forms.
The mechanism of deriving a new class from an existing one.
Bundling data and methods that operate on the data within a single unit.
The process of hiding the implementation details of an object.
What is inheritance in OOP?
The ability of an object to take on many forms.
The mechanism of deriving a new class from an existing one.
Bundling data and methods that operate on the data within a single unit.
The process of hiding the implementation details of an object.
What is polymorphism in OOP?
The ability of an object to take on many forms.
The mechanism of deriving a new class from an existing one.
Bundling data and methods that operate on the data within a single unit.
The process of hiding the implementation details of an object.
What is the purpose of a method in Java?
To define the data types of variables.
To declare a new class.
To perform a specific task or operation.
To handle errors during program execution.
Which keyword is used to define a method in Java?
function
method
void (sometimes, but not always the defining keyword)
The method name followed by parentheses ()
What are parameters in a method?
The return value of the method.
Variables that receive values when the method is called.
Keywords used to define the method's access level.
The name of the method.
Which class is commonly used to get input from the user in Java?
System
PrintStream
Scanner
InputStream
Which method of the System.out object is used to print output to the console without a newline character at the end?
println()
print()
printf()
format()
What is an exception in Java?
A normal event during program execution.
An error that occurs during the compilation phase.
An event that disrupts the normal flow of the program.
A reserved keyword in Java.
Which block is used to enclose code that might throw an exception?
catch
finally
try
throw
Which block is used to handle an exception that has occurred?
try
finally
catch
throws
Which of the following primitive data types in Java is used to store single characters?
String
char
byte
short
What is the size in bits of the int primitive data type in Java?
8 bits
16 bits
32 bits
64 bits
Which primitive data type is used to store whole numbers without decimal points and typically occupies the least amount of memory?
int
long
short
byte
Which primitive data type is used to store floating-point numbers with single-precision?
double
float
long
decimal
Which primitive data type is used to store large whole numbers that might exceed the range of an int?
short
byte
long
float
What is the default value of a boolean primitive data type if it's declared as an instance variable (member of a class) but not explicitly initialized?
true
false
null
0
What is the range of values that a byte primitive data type can hold in Java?
0 to 255
-128 to 127
-32768 to 32767
Approximately -2 billion to +2 billion
Which of the following is a valid literal for a char primitive data type?
'abc'
"a"
'a'
a
What happens if you try to store a value larger than the maximum range of an int into an int variable without explicit casting?
The program will throw a runtime exception.
The value will be automatically rounded.
The value will overflow, potentially leading to unexpected results (e.g., wrapping around to negative values).
The compiler will issue an error.
Which primitive data type in Java is 64 bits and designed for more precise floating-point calculations?
float
long
double
BigDouble
Which primitive type is for integers?
boolean
char
double
long
Which of the following is NOT a Java primitive type
double
float
int
String
What is each repetition of a loop known as?
cycle
revlolution
orbit
iteration
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
Which primitive data type represents an 8-bit signed integer?
short
int
byte
char
Which primitive data type represents a 64-bit floating-point number?
float
double
long
int
Which primitive data type represents a 16-bit Unicode character?
short
char
boolean
byte
Which primitive data type represents a logical value?
int
float
boolean
String
Which primitive data type represents a 32-bit signed integer?
long
int
short
byte
Which primitive data type represents a 64-bit signed integer?
long
int
short
byte
Which primitive data type represents a 32-bit single-precision floating-point number?
double
float
long
int
Which data type can hold the value true or false?
char
int
boolean
String
