Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 921–930 of 958 questions
Q.921 Easy Basics & Syntax
Which of the following statements about Java packages is correct?
A Package names must be in uppercase
B Package names use dot notation for hierarchy
C A single Java file can belong to multiple packages
D Package statement must appear after import statements
Correct Answer:  B. Package names use dot notation for hierarchy
EXPLANATION

Package names follow a hierarchical structure using dots (e.g., com.example.app). Package statement must be the first non-comment statement.

Take Test
Q.922 Easy Basics & Syntax
Which keyword is used to prevent method overriding in Java?
A abstract
B final
C static
D synchronized
Correct Answer:  B. final
EXPLANATION

The 'final' keyword prevents a method from being overridden by subclasses.

Take Test
Q.923 Easy Basics & Syntax
Which of the following is NOT a valid Java identifier?
A _variable123
B $myVar
C 123variable
D my_Var$
Correct Answer:  C. 123variable
EXPLANATION

Java identifiers cannot start with a digit. Valid identifiers must start with a letter, underscore, or dollar sign.

Take Test
Q.924 Easy Basics & Syntax
What will be the output of: System.out.println(Math.max(5, 10) - Math.min(3, 8));
A 2
B 5
C 7
D 15
Correct Answer:  C. 7
EXPLANATION

Math.max(5, 10) = 10, Math.min(3, 8) = 3. So 10 - 3 = 7.

Take Test
Q.925 Medium Basics & Syntax
Which statement about Java's 'this' keyword is correct?
A 'this' refers to the parent class
B 'this' refers to the current object instance
C 'this' is a static reference
D 'this' cannot be used in constructors
Correct Answer:  B. 'this' refers to the current object instance
EXPLANATION

'this' is a reference to the current object instance. It's used to distinguish instance variables from parameters and to call other constructors.

Take Test
Advertisement
Q.926 Medium Basics & Syntax
What is the output of: double d = 5.7; int i = (int) d; System.out.println(i);
A 6
B 5.7
C 5
D Error
Correct Answer:  C. 5
EXPLANATION

Explicit casting from double to int truncates the decimal part. 5.7 becomes 5 (not rounded).

Take Test
Q.927 Medium Basics & Syntax
What will be the output: int a = 10; int b = 20; System.out.println(a > b ? "A" : "B");
A A
B B
C Error
D AB
Correct Answer:  B. B
EXPLANATION

Ternary operator: condition ? trueValue : falseValue. Since 10 > 20 is false, "B" is printed.

Take Test
Q.928 Medium Basics & Syntax
Which of the following correctly initializes a 2D array in Java?
A int[][] arr = new int[3][4];
B int[] arr[] = new int[3][4];
C Both A and B
D Neither A nor B
Correct Answer:  C. Both A and B
EXPLANATION

Both syntaxes are valid in Java for declaring 2D arrays. The brackets can be placed after the type or variable name.

Take Test
Q.929 Medium Basics & Syntax
What is the output of: System.out.println("5" + 3 + 2);
A 10
B 532
C Error
D 7
Correct Answer:  B. 532
EXPLANATION

String concatenation: "5" + 3 becomes "53", then "53" + 2 becomes "532". Once a String is involved, + performs concatenation.

Take Test
Q.930 Easy Basics & Syntax
What will be the output: String s = "Hello"; System.out.println(s.charAt(1));
A H
B e
C l
D o
Correct Answer:  B. e
EXPLANATION

charAt() uses 0-based indexing. Index 1 refers to the second character, which is 'e' in "Hello".

Take Test
IGET
iget AI
Online · Ask anything about exams
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