Java Programming
Java OOP, collections, multithreading
270 Questions 10 Topics Take Test
Advertisement
Showing 251–260 of 270 questions
Q.251 Easy Basics & Syntax
Consider the code: int x = 5; x += 3; What is the value of x?
A 5
B 8
C 3
D 53
Correct Answer:  B. 8
EXPLANATION

The compound assignment operator += means x = x + 3. So 5 + 3 = 8.

Take Test
Q.252 Easy Basics & Syntax
What will be the output of: System.out.println(10 / 3);
A 3.33
B 3
C 3.333333
D Compilation Error
Correct Answer:  B. 3
EXPLANATION

Both operands are integers, so integer division is performed. Result is 3 (not 3.33). To get decimal, at least one operand must be float/double.

Take Test
Q.253 Easy Basics & Syntax
What is the purpose of the 'instanceof' operator?
A To create new instances
B To check if an object is an instance of a class
C To compare object values
D To delete object instances
Correct Answer:  B. To check if an object is an instance of a class
EXPLANATION

The 'instanceof' operator is used to check if an object is an instance of a specific class or implements a specific interface.

Take Test
Q.254 Easy Basics & Syntax
What does the 'super' keyword do in Java?
A Refers to the current object
B Refers to the parent class
C Creates a new instance
D Marks a method as superior
Correct Answer:  B. Refers to the parent class
EXPLANATION

The 'super' keyword is used to refer to parent class members and invoke parent class constructors.

Take Test
Q.255 Easy Basics & Syntax
Which of the following is a valid variable declaration?
A int 2num;
B int num-2;
C int num$2;
D int num.2;
Correct Answer:  C. int num$2;
EXPLANATION

Variable names can contain letters, digits, underscores, and dollar signs, but cannot start with a digit or contain hyphens or dots.

Take Test
Advertisement
Q.256 Easy Basics & Syntax
What is the correct way to declare a constant in Java?
A const int MAX = 100;
B static int MAX = 100;
C public static final int MAX = 100;
D final static int MAX = 100;
Correct Answer:  C. public static final int MAX = 100;
EXPLANATION

'const' is not a Java keyword. The correct convention for constants is public static final. Option D also works but C follows the standard convention.

Take Test
Q.257 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.258 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.259 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.260 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
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