Java Programming
Java OOP, collections, multithreading
270 Questions 10 Topics Take Test
Advertisement
Showing 261–270 of 270 questions
Q.261 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
Q.262 Easy Basics & Syntax
Which of the following is the correct syntax for a multi-line comment in Java?
A // This is a comment
B /* This is a comment */
C
D # This is a comment
Correct Answer:  B. /* This is a comment */
EXPLANATION

Multi-line comments in Java use /* */ syntax. Single-line comments use //. Other syntaxes are for different languages.

Take Test
Q.263 Easy Basics & Syntax
What will be printed? float f = 5.5f; System.out.println(f);
A 5.5
B 5.50
C Error
D 5
Correct Answer:  A. 5.5
EXPLANATION

The 'f' suffix indicates a float literal. The output will be 5.5 (trailing zeros are not shown in standard printing).

Take Test
Q.264 Easy Basics & Syntax
Which of the following is a valid variable name in Java?
A 123abc
B _myVar
C my-Var
D class
Correct Answer:  B. _myVar
EXPLANATION

Variable names must start with a letter, underscore (_), or dollar sign ($). They cannot start with digits, contain hyphens, or be reserved keywords.

Take Test
Q.265 Easy Basics & Syntax
Which keyword is used to prevent a class from being inherited?
A static
B abstract
C final
D private
Correct Answer:  C. final
EXPLANATION

The 'final' keyword prevents a class from being extended/inherited. A final class cannot have subclasses.

Take Test
Advertisement
Q.266 Easy Basics & Syntax
What will be the output of: System.out.println(5 / 2);
A 2.5
B 2
C 2.0
D Error
Correct Answer:  B. 2
EXPLANATION

Integer division in Java results in an integer. 5/2 = 2 (remainder is discarded). To get 2.5, at least one operand must be float/double.

Take Test
Q.267 Easy Basics & Syntax
What will be the output of: boolean flag = true; System.out.println(!flag);
A true
B false
C !true
D Compilation error
Correct Answer:  B. false
EXPLANATION

The logical NOT operator (!) inverts the boolean value. !true becomes false.

Take Test
Q.268 Easy Basics & Syntax
What will be the output of the following code? int x = 5; x += 3; System.out.println(x);
A 3
B 5
C 8
D 53
Correct Answer:  C. 8
EXPLANATION

The += operator adds the right operand to the left operand. x += 3 is equivalent to x = x + 3, so 5 + 3 = 8.

Take Test
Q.269 Easy Basics & Syntax
Which keyword is used to create a constant variable in Java?
A const
B constant
C final
D immutable
Correct Answer:  C. final
EXPLANATION

The 'final' keyword is used to declare constants in Java. Once assigned, the value cannot be changed.

Take Test
Q.270 Easy Basics & Syntax
Which of the following is the correct syntax to declare a variable in Java?
A int x = 10;
B int x: 10;
C x int = 10;
D int: x = 10;
Correct Answer:  A. int x = 10;
EXPLANATION

Java uses the syntax 'datatype variableName = value;' for variable declaration.

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