Which of the following is the correct way to declare a variable in Java?
A
int = x 5; B
int x = 5; C
x int = 5; D
declare int x = 5;
Analysis & Theory
In Java, variables are declared with the type first: `int x = 5;`.
Which statement is used to output text in Java?
A
print() B
System.out.print() C
console.log() D
echo()
Analysis & Theory
`System.out.print()` or `System.out.println()` is used to display output in Java.
What is the correct way to start a class in Java?
A
function MyClass { B
class MyClass { C
public: MyClass() D
define class MyClass
Analysis & Theory
Java classes are defined with `class MyClass {`.
Which keyword is used to define a method that does not return anything?
A
void B
null C
empty D
nothing
Analysis & Theory
The `void` keyword specifies that a method does not return a value.
How do you write a single-line comment in Java?
A
# This is a comment B
// This is a comment C
<!-- This is a comment --> D
/* This is a comment */
Analysis & Theory
`//` is used for single-line comments in Java.
What symbol is used to end a statement in Java?
A
. B
: C
; D
/
Analysis & Theory
In Java, every statement ends with a semicolon (`;`).
Which of the following is a valid method declaration in Java?
A
void method() B
method void() C
define method() D
public method:
Analysis & Theory
A valid method declaration includes the return type before the method name: `void method()`.
How do you write a block of code in Java?
A
Using `[]` brackets B
Using `()` parentheses C
Using `{}` curly braces D
Using `<>` angle brackets
Analysis & Theory
Java uses `{}` curly braces to define blocks of code.
Which of the following is a valid `main` method signature?
A
public void main(String args) B
public static void main(String[] args) C
static void main(String args[]) D
main(String[] args)
Analysis & Theory
`public static void main(String[] args)` is the standard entry point for Java applications.
Which keyword is used to create an object in Java?
A
create B
new C
init D
class
Analysis & Theory
The `new` keyword is used to create new objects in Java.