Java Programming
Java OOP, collections, multithreading
270 Questions 10 Topics Take Test
Advertisement
Showing 241–250 of 270 questions
Q.241 Easy Basics & Syntax
Consider the following code snippet. What is the primary purpose of the 'final' keyword when applied to a class in Java?
A Prevents the class from being instantiated
B Prevents the class from being inherited by other classes
C Makes all methods in the class abstract
D Allows the class to be accessed globally without import
Correct Answer:  B. Prevents the class from being inherited by other classes
EXPLANATION

The 'final' keyword when applied to a class prevents it from being extended or inherited. This is a fundamental OOP concept in Java used to restrict inheritance.

Take Test
Q.242 Easy Basics & Syntax
What is the output of: System.out.println(5 > 3 ? "Yes" : "No");?
A 5
B 3
C Yes
D No
Correct Answer:  C. Yes
EXPLANATION

This uses the ternary operator (conditional operator). The condition 5 > 3 is true, so it returns the value after the '?', which is "Yes".

Take Test
Q.243 Easy Basics & Syntax
Which of the following is NOT a Java keyword?
A synchronized
B volatile
C thread
D transient
Correct Answer:  C. thread
EXPLANATION

'thread' is not a Java keyword. 'synchronized', 'volatile', and 'transient' are all valid Java keywords used for special purposes.

Take Test
Q.244 Easy Basics & Syntax
Which of the following is true about the 'break' statement?
A It terminates the entire program
B It skips the current iteration of a loop
C It exits the current loop or switch statement
D It jumps to the next iteration
Correct Answer:  C. It exits the current loop or switch statement
EXPLANATION

'break' statement exits the innermost loop or switch statement. It doesn't skip the current iteration (that's 'continue') and doesn't terminate the entire program.

Take Test
Q.245 Easy Basics & Syntax
What is the output of: System.out.println(10 / 3);?
A 3.333...
B 3.33
C 3
D 4
Correct Answer:  C. 3
EXPLANATION

When dividing two integers, Java performs integer division and returns an integer result. 10 / 3 = 3 (remainder is discarded). To get decimal result, at least one operand should be a float or double.

Take Test
Advertisement
Q.246 Easy Basics & Syntax
What is the size of 'long' data type in Java?
A 16 bits
B 32 bits
C 64 bits
D Platform dependent
Correct Answer:  C. 64 bits
EXPLANATION

In Java, the 'long' data type is always 64 bits, regardless of the platform. This is one of Java's strengths - its size specifications are platform-independent.

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

The += operator is an assignment operator that adds the right operand to the left operand and assigns the result. So x += 3 means x = x + 3, which is 5 + 3 = 8.

Take Test
Q.248 Easy Basics & Syntax
What will be the result of: int a = 10; int b = 20; System.out.println(a + b + "Java");?
A "30Java"
B "1020Java"
C "Java30"
D Compilation error
Correct Answer:  A. "30Java"
EXPLANATION

When + operator is used with numeric values first, they are added (10 + 20 = 30), and then concatenated with the string "Java", resulting in "30Java".

Take Test
Q.249 Easy Basics & Syntax
Which keyword is used to create a constant variable in Java that cannot be modified after initialization?
A static
B const
C final
D immutable
Correct Answer:  C. final
EXPLANATION

The 'final' keyword is used to declare constants in Java. Once a final variable is assigned a value, it cannot be changed. 'const' is a reserved keyword but not used in Java.

Take Test
Q.250 Easy Basics & Syntax
Which of the following is a valid method name in Java?
A 2ndMethod()
B _myMethod()
C my-method()
D my method()
Correct Answer:  B. _myMethod()
EXPLANATION

Method names must start with a letter, underscore, or dollar sign. '_myMethod()' is valid. Names cannot start with digits, contain hyphens, or spaces.

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