Home Subjects Java Programming Basics & Syntax

Java Programming
Basics & Syntax

Java OOP, collections, multithreading

50 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 41–50 of 50
Topics in Java Programming
Q.41 Medium Basics & Syntax
What will be the output: System.out.println('A' + 'B');
A AB
B 131
C Error
D 2
Correct Answer:  B. 131
EXPLANATION

Characters are treated as their ASCII values in arithmetic operations. 'A' (65) + 'B' (66) = 131.

Test
Q.42 Medium Basics & Syntax
Which of the following is the correct way to declare and initialize an array in Java?
A int array[5] = {1, 2, 3, 4, 5};
B int[] array = {1, 2, 3, 4, 5};
C int array = [1, 2, 3, 4, 5];
D array[5] int = {1, 2, 3, 4, 5};
Correct Answer:  B. int[] array = {1, 2, 3, 4, 5};
EXPLANATION

The correct syntax is 'datatype[] arrayName = {elements};' or 'datatype[] arrayName = new datatype[size];'

Test
Q.43 Medium Basics & Syntax
Identify the output: System.out.println("Java".length());
A 4
B 5
C Compilation error
D null
Correct Answer:  A. 4
EXPLANATION

The length() method returns the number of characters in the string "Java", which is 4 characters.

Test
Q.44 Medium Basics & Syntax
Which statement is correct about Java variables?
A Variable names are case-sensitive
B Variable names can start with a digit
C Variable names can contain spaces
D Variable names can use special characters like @, #
Correct Answer:  A. Variable names are case-sensitive
EXPLANATION

Java variable names are case-sensitive. 'age' and 'Age' are different variables. Names cannot start with digits, cannot contain spaces, and special characters are not allowed.

Test
Q.45 Medium Basics & Syntax
What is the output of: System.out.println(5 > 3 ? 'A' : 'B');
A A
B B
C true
D Compilation error
Correct Answer:  A. A
EXPLANATION

The ternary operator (?:) evaluates the condition (5 > 3, which is true) and returns the first value 'A'.

Test
Q.46 Medium Basics & Syntax
Which operator has the highest precedence in Java?
A * / %
B + -
C () []
D == !=
Correct Answer:  C. () []
EXPLANATION

Parentheses () and array access [] have the highest precedence in Java. Multiplication, division, and modulo come next, followed by addition and subtraction.

Test
Q.47 Medium Basics & Syntax
What is the output of: System.out.println(10 / 3);
A 3.33
B 3
C 3.0
D 3.333333
Correct Answer:  B. 3
EXPLANATION

When both operands are integers, the division result is an integer. 10 / 3 = 3 (integer division, not floating-point).

Test
Q.48 Medium Basics & Syntax
Which of the following will compile without error? public static void main(String args[]) { int x = 10; final int y = 20; y = 30; }
A Yes, it will compile
B No, compilation error on y = 30
C No, compilation error on final declaration
D No, compilation error on main method
Correct Answer:  B. No, compilation error on y = 30
EXPLANATION

Once a final variable is assigned, it cannot be reassigned. The line 'y = 30;' will cause a compilation error.

Test
Q.49 Medium Basics & Syntax
What is the size of 'char' data type in Java?
A 1 byte
B 2 bytes
C 4 bytes
D 8 bytes
Correct Answer:  B. 2 bytes
EXPLANATION

The 'char' data type in Java is 2 bytes (16 bits) because it uses Unicode character encoding.

Test
Q.50 Medium Basics & Syntax
Which of the following is NOT a primitive data type in Java?
A int
B boolean
C String
D double
Correct Answer:  C. String
EXPLANATION

String is a non-primitive (reference) data type in Java. Primitive types include int, boolean, double, float, char, long, short, byte.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips