Home Subjects Java Programming

Java Programming

Java OOP, collections, multithreading

958 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 851–860 of 958
Topics in Java Programming
Q.851 Medium OOP in Java
What will happen when you try to instantiate an interface in Java?
A It will create an instance successfully
B It will throw a RuntimeException
C It will cause a compilation error
D It depends on the JVM version
Correct Answer:  C. It will cause a compilation error
EXPLANATION

Interfaces cannot be instantiated directly. You must create a class that implements the interface. Attempting this causes a compilation error.

Take Test
Q.852 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.853 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.854 Medium OOP in Java
Which of the following statements about abstract classes is TRUE?
A Abstract classes can be instantiated
B Abstract classes cannot have concrete methods
C Abstract classes can have abstract methods and concrete methods
D Abstract classes must extend another abstract class
Correct Answer:  C. Abstract classes can have abstract methods and concrete methods
EXPLANATION

Abstract classes can contain both abstract methods (without implementation) and concrete methods (with implementation). They cannot be instantiated directly.

Take Test
Q.855 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.856 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.857 Medium OOP in Java
What is the output of the following code?

class A {
int x = 10;
}
class B extends A {
int x = 20;
}
public class Test {
public static void main(String[] args) {
A obj = new B();
System.out.println(obj.x);
}
}
A 10
B 20
C Compilation Error
D Runtime Error
Correct Answer:  A. 10
EXPLANATION

Variable overriding doesn't work in Java like method overriding. obj.x accesses the variable from reference type A, which has value 10.

Take Test
Q.858 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.859 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.860 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
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