Java Programming
Java OOP, collections, multithreading
958 Questions 10 Topics Take Test
Advertisement
Showing 881–890 of 958 questions
Q.881 Medium Basics & Syntax
Which statement about constructors is INCORRECT?
A Constructors can be overloaded
B Constructors must return a value
C Constructors are called automatically when an object is created
D A class can have multiple constructors
Correct Answer:  B. Constructors must return a value
EXPLANATION

Constructors do NOT have a return type, not even void. They automatically initialize objects when created. They can be overloaded and a class can have multiple constructors with different parameters.

Take Test
Q.882 Medium Basics & Syntax
What is the difference between 'break' and 'continue' in loop statements?
A Both terminate the loop
B break exits the loop; continue skips current iteration
C continue exits the loop; break skips current iteration
D They have the same functionality
Correct Answer:  B. break exits the loop; continue skips current iteration
EXPLANATION

'break' immediately exits the loop, while 'continue' skips the remaining statements in the current iteration and jumps to the next iteration.

Take Test
Q.883 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.884 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
Q.885 Medium Basics & Syntax
Which access modifier allows a member to be accessible only within the same package?
A public
B private
C protected
D default (no modifier)
Correct Answer:  D. default (no modifier)
EXPLANATION

When no access modifier is specified, it's called package-private or default access. Members with default access are accessible only within the same package, not from other packages.

Take Test
Q.886 Medium Basics & Syntax
What will happen if you try to access an index out of bounds in an array?
A Returns 0
B Returns null
C Throws ArrayIndexOutOfBoundsException
D Compilation error
Correct Answer:  C. Throws ArrayIndexOutOfBoundsException
EXPLANATION

Accessing an array index that doesn't exist throws an ArrayIndexOutOfBoundsException at runtime. This is a checked exception that must be handled or declared.

Take Test
Q.887 Medium Basics & Syntax
Which of the following statements about static methods is correct?
A Static methods can access instance variables directly
B Static methods can be overridden by subclasses
C Static methods can only be called using the class name
D Static methods must have a return type
Correct Answer:  C. Static methods can only be called using the class name
EXPLANATION

Static methods belong to the class, not to any instance. They are called using the class name (e.g., ClassName.methodName()). They cannot directly access instance variables and cannot be overridden (though they can be hidden).

Take Test
Q.888 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.889 Medium Basics & Syntax
Which of the following correctly demonstrates method overloading?
A Two methods with same name and same parameters in different classes
B Two methods with same name but different number or type of parameters in the same class
C Two methods with different names and different parameters in the same class
D Two methods with same name and return type in the same class
Correct Answer:  B. Two methods with same name but different number or type of parameters in the same class
EXPLANATION

Method overloading allows multiple methods with the same name but different parameters (number, type, or order) in the same class. This is a way to implement compile-time (static) polymorphism.

Take Test
Q.890 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
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