Java Programming
Java OOP, collections, multithreading
270 Questions 10 Topics Take Test
Advertisement
Showing 231–240 of 270 questions
Q.231 Easy OOP in Java
Which of the following correctly describes the 'this' keyword?
A Refers to the parent class
B Refers to the current object instance
C Refers to the class itself
D Refers to the method
Correct Answer:  B. Refers to the current object instance
EXPLANATION

'this' is a reference to the current object instance. It's used to refer to instance variables, call other constructors, or pass object reference.

Take Test
Q.232 Easy OOP in Java
Which interface in Java represents a collection that does not allow duplicate elements?
A List
B Set
C Queue
D Map
Correct Answer:  B. Set
EXPLANATION

Set interface ensures uniqueness and doesn't allow duplicate elements. HashSet, TreeSet are implementations of Set.

Take Test
Q.233 Easy OOP in Java
What is the purpose of the 'super' keyword in Java?
A To refer to the current object
B To refer to the parent class members
C To create a new object
D To call static methods
Correct Answer:  B. To refer to the parent class members
EXPLANATION

The 'super' keyword is used to refer to the immediate parent class object. It's used to access parent class methods and constructors.

Take Test
Q.234 Easy OOP in Java
What will be the output?

class Parent {
void show() {
System.out.println("Parent");
}
}
class Child extends Parent {
void show() {
System.out.println("Child");
}
}
parent obj = new Child();
obj.show();
A Parent
B Child
C Compilation Error
D Runtime Error
Correct Answer:  B. Child
EXPLANATION

This demonstrates method overriding and polymorphism. The actual object type is Child, so Child's show() method is called.

Take Test
Q.235 Easy OOP in Java
Which access modifier allows a member to be accessed only within the same package?
A public
B private
C protected
D default (package-private)
Correct Answer:  D. default (package-private)
EXPLANATION

Default access (no modifier) allows access only within the same package. Protected allows same package and subclasses.

Take Test
Q.236 Easy OOP in Java
Which of the following is NOT a pillar of Object-Oriented Programming?
A Abstraction
B Polymorphism
C Compilation
D Encapsulation
Correct Answer:  C. Compilation
EXPLANATION

The four pillars of OOP are Abstraction, Encapsulation, Inheritance, and Polymorphism. Compilation is a process, not a pillar of OOP.

Take Test
Q.237 Easy Basics & Syntax
Which of the following is a valid declaration of a two-dimensional array in Java that can store 3 rows and 4 columns of integers?
A int arr[][] = new int[3][4];
B int[] arr[] = new int[3][4];
C int[][] arr = new int[3][4];
D All of the above
Correct Answer:  D. All of the above
EXPLANATION

All three declarations are syntactically valid in Java and represent the same 2D array structure. The position of brackets doesn't matter for 2D array declaration - they all create a 3x4 integer array.

Take Test
Q.238 Easy Basics & Syntax
Consider the following code. What will be printed?
String s = "Java";
s = s.concat(" Programming");
System.out.println(s.length());
A 4
B 8
C 17
D 19
Correct Answer:  C. 17
EXPLANATION

"Java" has 4 characters. After concatenation with " Programming" (12 characters including space), the total length is 4 + 13 = 17 characters.

Take Test
Q.239 Easy Basics & Syntax
What will happen when you execute the following code?
int[] arr = new int[5];
System.out.println(arr[5]);
A Output: 0
B Output: null
C ArrayIndexOutOfBoundsException at runtime
D Compilation error
Correct Answer:  C. ArrayIndexOutOfBoundsException at runtime
EXPLANATION

An array of size 5 has valid indices from 0 to 4. Accessing arr[5] throws ArrayIndexOutOfBoundsException at runtime because index 5 is out of bounds.

Take Test
Q.240 Easy Basics & Syntax
Which of the following statements about Java's garbage collection is TRUE?
A Garbage collection is guaranteed to run at specific time intervals
B The programmer must explicitly call System.gc() to free memory
C Garbage collection automatically reclaims memory used by unreferenced objects
D Java does not have automatic garbage collection mechanism
Correct Answer:  C. Garbage collection automatically reclaims memory used by unreferenced objects
EXPLANATION

Java's garbage collector automatically identifies and reclaims memory of objects that are no longer referenced. While System.gc() can be suggested, it's not guaranteed to execute immediately.

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