60 Questions
Which of the following is a primitive datatype in Java?
integer
Which operator is used for incrementing the value of a variable by 1 in Java?
++
Which operator is used for performing arithmetic operations in Java?
What does the following code snippet do?
int x = 5; x += 3;
Assigns the value 8 to x
Which of the following is a conditional statement in Java?
if
What is the purpose of the logical operator && in Java?
Perform logical AND operation
Which of the following is NOT an access specifier in Java?
package
What is the return type of a method that does not return any value?
void
What is the purpose of arguments/parameters in a method?
To pass values to the method for processing
What is the difference between function declaration and function definition in Java?
Function declaration is the prototype of the function, while function definition contains the body of the function
What happens when a method is called in Java?
The program starts searching for the function definition
What is method overloading in Java?
Defining multiple methods with the same name and different arguments
Which of the following is an alternative to if...else statement in Java?
Switch case
What is the purpose of the 'break' statement in switch case?
To terminate a specific iteration of a loop
Which type of loop in Java is entry-controlled?
For loop
What is the syntax for a method in Java?
Access_specifier return_type method_name (arguments) { Body of the method; }
What is the purpose of the 'continue' statement in a loop?
To terminate a specific iteration of a loop
Which type of loop in Java is exit-controlled?
Do...while loop
Which one of the following is an example of a class in Java?
Car
Which one of the following is an example of an object in Java?
Car
What is the syntax for defining a class in Java?
access_specifier class className { Class definition containing variables and methods; }
What is an object in Java?
An instance of a class
What are comments used for in Java?
To increase the understanding and readability of the program
What are the rules for writing a Java program?
Java uses higher CamelCase for writing class names and lower camelCase for writing method names
Which keyword is used to declare the main method in a Java program?
static
What is the purpose of the 'System.out.print()' method in Java?
To display something on the screen during program execution
What is the purpose of the 'println()' method in Java?
To move the cursor to the next line after printing
What is the role of the 'String args[]' in the main method of a Java program?
It is an array of strings that stores arguments passed by the command line
Why does the main method in a Java program have to be declared static?
To allow main() to be called without creating an object of the class
What is the purpose of the 'public' keyword in Java?
To specify the visibility of a class or method
Which of the following is a bitwise operator in Java?
&
What is the result of the expression 'x += 5' in Java?
x + 5
Which type of loop in Java is exit-controlled?
do-while loop
What is the purpose of the '==' operator in Java?
Comparison
Which of the following is NOT a primitive datatype in Java?
String
What is the purpose of the 'else if' statement in Java?
To check multiple conditions
Which keyword is used to declare the main method in a Java program?
main
What is the purpose of the 'public' keyword in Java?
To specify the access level of a class, method, or variable
What is the purpose of the 'continue' statement in a loop?
To skip the current iteration and move to the next iteration
Which type of loop in Java is exit-controlled?
Do-while loop
What is the purpose of the logical operator && in Java?
To perform logical AND operation
What are comments used for in Java?
To explain the functionality of the code
Which keyword is used to declare a method in Java?
public
What is the return type of a method that does not return any value?
void
What is the purpose of arguments/parameters in a method?
To pass values to the method
What is the purpose of the 'println()' method in Java?
To print the value of a variable
What is method overloading in Java?
Defining multiple methods with the same name but different arguments
What is the purpose of the 'continue' statement in a loop?
To skip the current iteration of the loop and move to the next iteration
Which type of loop in Java is exit-controlled?
Do...while loop
What is the purpose of the 'continue' statement in Java?
To terminate a particular iteration of a loop
What is the purpose of the 'break' statement in Java?
To terminate the entire loop and come out of it
What is the purpose of methods in Java?
To make the program modular and simpler
What is the syntax for a method in Java?
Access_specifier return_type method_name (arguments) { Body of the method; }
Which type of loop in Java is entry-controlled?
For loop
Which one of these is a correct statement about classes and objects in Java?
A class is a blueprint or template for creating objects.
What is the purpose of comments in Java?
To increase the understanding and readability of the program.
Which of the following is a rule for writing a Java program?
Variable names should start with an alphabet or an underscore (_).
What is the role of the 'String args[]' in the main method of a Java program?
It is used to pass command-line arguments to the program.
What is the purpose of the 'public' keyword in Java?
It is an access specifier that allows the method to be accessed from anywhere.
What is an alternative to the if...else statement in Java?
The switch statement.
Test your knowledge of conditional statements and switch case structures with this quiz! Learn about different ways to execute instructions based on specific conditions and find out how to determine the day of the week using these structures.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free