Which of the following correctly declares multiple variables in Java?
A
int a = 5, b = 10, c = 15; B
int a = b = c = 5; C
int a = 5 int b = 10; D
a, b, c = 5;
Analysis & Theory
You can declare and initialize multiple variables in a single line using commas.
What is the output of:
int x = 1, y = 2;
System.out.println(x + y);
A
12 B
3 C
x + y D
Error
Analysis & Theory
`1 + 2` equals 3.
Which of the following is NOT allowed in Java?
A
int a = 1, b = 2; B
String s1 = "Hi", s2 = "Hello"; C
double x = 5.5, int y = 6; D
char c1 = 'A', c2 = 'B';
Analysis & Theory
You cannot mix data types in a single declaration.
How many variables are declared in this line?
int a = 1, b = 2, c = 3;
A
1 B
2 C
3 D
0
Analysis & Theory
Three variables `a`, `b`, and `c` are declared and initialized.
Which line correctly updates values of multiple variables?
A
a = 5, b = 6; B
a: 5; b: 6; C
a = 5; b = 6; D
update a = 5 b = 6;
Analysis & Theory
Separate assignment statements with semicolons.
What is the output?
int a = 5, b = 10;
System.out.println("Sum: " + (a + b));
A
Sum: 510 B
Sum: 15 C
15Sum: D
Error
Analysis & Theory
`a + b` = 15, so output is `Sum: 15`.
Which of the following declares three uninitialized `int` variables?
A
int a = b = c; B
int a; int b; int c; C
int a, b, c; D
int a: b: c;
Analysis & Theory
`int a, b, c;` declares three variables without initializing.
What happens if you try to use a variable that is declared but not initialized?
A
It defaults to 0 B
It compiles and runs C
Compiler error D
It prints null
Analysis & Theory
Local variables must be initialized before use; otherwise, a compiler error occurs.
What is the output?
int x = 3, y = 4;
System.out.println("x: " + x + ", y: " + y);
A
x: x, y: y B
x: 3 y: 4 C
x: 3, y: 4 D
Error
Analysis & Theory
Variables are concatenated into the string.
Which of the following lines contains a syntax error?
A
int a = 10, b = 20; B
double x = 1.1, y = 2.2; C
char c1 = 'A', c2 = 'B'; D
int a = 1; b = 2;
Analysis & Theory
`b = 2;` is invalid if `b` was not declared before.