Below are 25 Java Interview Questions. This is first set of Multiple choice questions. This will help in basic understanding of JAVA concepts and helps prepare you for your next JAVA interview :

Top 25 Java Interview Questions

Question 1

Which error occurs first?

  1. a) Compile time error
  2. b) Run time error
  3. c) Checked Exception
  4. d) Un checked exception

Ans : a

 

Question 2

Which language is platform independent?

  1. a) PHP
  2. b) HTML
  3. c) Java
  4. d) .Net

Ans : c

 

Question 3

How to define method overriding?

  1. a) Method overriding is the concept of declaring method with same name in same class.
  2. b) If a method with same return type and name is declared in child class then its called method overriding.
  3. c) If a method with same name with different return type and different number of parameters in child class then its called method overriding.
  4. d) All of the above.

Ans : b

 

Question 4

Abstraction can be achieved with?

  1. a) inheritance
  2. b) Multiple Inheritance
  3. c) Abstraction classes
  4. d) Interface and abstract classes

Ans : d

 

Question 5 

In what case an exception is thrown even the code is wrapped with try/catch?

  1. a) Exception occurred inside catch block.
  2. b) Exception occurred in try block.
  3. c) Compile time error occurred in main method
  4. d) Null pointer exception occurred in finally.

Ans : a

 

Question 6

How many instance a singleton class can have?

  1. a) Any numbers
  2. b) Only one
  3. c) Depends on number of constructor
  4. d) 7

Ans : b

 

Question 7

Which method is called if main is not a static?

  1. a) static block whichever is on top of the class
  2. b) Throws NoSuchMethodError
  3. c) Calls main method even it’s not static
  4. d) Runs all static methods and skip main method

Ans : b

 

Question 8

Can a class named “Question” can have constructor with different name?

  1. a) Yes, If the method is called from the constructor then it will act as a constructor
  2. b) Yes if it is same as parent class name
  3. c) Yes, if it defined as static final
  4. d) No it’s not possible

Ans : d

 

 

Question 9

How many ways are there to create an object in java?

  1. a) 1
  2. b) 3
  3. c) 4
  4. d) 2

Ans : c

 

Question 10

Which of following class is not a part of java.util.concurrent package?

  1. a) Callable
  2. b) ExecutorService
  3. c) CompletionServices
  4. d) Executors

Ans : c

 

Question 11

Which version of java introduced Lambda expressions?

  1. a) Java 8
  2. b) Java 6
  3. c) Java 9
  4. d) It’s not in Java, it is in C++

Ans : a

 

Question 12

In Java, we pass always a reference in methods, so is it pass by value or pass by reference?

  1. a) Pass by reference
  2. b) Pass by value
  3. c) It’s both depends on the coding
  4. d) It’s neither pass by reference and nor pass by value. It’s pass by method.

Ans : b

 

Question 13

If value of any class can’t be changed, then what is it called?

  1. a) Read Only class
  2. b) POJO
  3. c) Write only class
  4. d) Immutable class

Ans : d

 

Question 14

What is it called if all nodes are covered with minimum number of edges?

  1. a) Linked list
  2. b) Hashmap
  3. c) Spanning tree
  4. d) Arraylist

Ans : c

 

Question 15

Can we access private method outside the class?

  1. a) Yes
  2. b) No
  3. c) Only possible in C++
  4. d) Accessing it will cause run time error.

Ans : a

 

Question 16

What comes under polymorphism?

  1. a) Abstraction
  2. b) Inheritance
  3. c) Java
  4. d) Method overloading

Ans : d

 

Question 17

If any interface has 3 methods then which of the following statement is correct about it’s implementation class?

  1. a) Implementation class will also have 3 methods
  2. b) Implementation class can have either less than or more than 3 but it can’t be 3.
  3. c) It can have more than 3 methods, but minimum 3 are required.
  4. d) Implementation is not required for compilation.

Ans : c

 

Question 18

What are local classes?

  1. a) There is nothing like local classes in java.
  2. b) It is a class which is private.
  3. c) Any class which is defined inside a block of the code and it’s can’t be access outside the block.
  4. d) Wrapper classes are called as local.

Ans : c

 

Question 19

Which block gives guarantee to execute the code?

  1. a) finally
  2. b) try
  3. c) catch
  4. d) for

Ans : a

 

Question 20

If one project has multiple classes and all of them have main method, which main method will compiler pick?

  1. a) Whatever comes first
  2. b) Only the one which is given in entry point class
  3. c) Throws error
  4. d) Compiler renames it first and execute only one main method with round robin

Ans : b

 

Question 21

What would be the output for below code snippet?

 

package question.paper;

public class Exam {

public static void main (String[] args){
Integer variable1 = 10;
System.out.println((variable1==10) ? “First” : “Second”);
}
}

 

  1. a) First
  2. b) Second
  3. c) Compile time error
  4. d) Run time error

Ans : a

 

Question 22

What would be the output for below code snippet?

 

package question.paper;

public class Exam {

public static void main (String[] args){
Integer variable1 = 10;

for(int i=2; i<variable1; i++){
System.out.print(i);
if(i==3)break;
}
}
}

 

  1. a) 234
  2. b) 0123
  3. c) 123
  4. d) 23

Ans : d

 

 

Question 23

What would be the output for below code snippet?

package question.paper;

public class Exam {

public static void main (String[] args){
do{
System.out.print(“25”);
}while(true==false);
System.out.println(“93”);
}
}

 

  1. a) Compile time error
  2. b) 2593
  3. c) 93
  4. d) infinite loop

Ans : b

 

Question 24

What would be the output for below code snippet?

 

package question.paper;

public class Exam {

public static void main (String[] args){
Integer variable1 = 10;

if(variable1==10)
System.out.print(20);
System.out.print(10);

if(variable1!=9)
System.out.print(“11”);
else
System.out.println(“10”);
}
}

 

  1. a) 20101110
  2. b) 2010
  3. c) 201011
  4. d) 2011

Ans : c

 

Question 25

What would be the output for below code snippet?

package question.paper;

public class Exam {

public static void main (String[] args){
Integer variable1 = 10;

switch(variable1){
case 1: System.out.print(“1”);
case 2: System.out.print(“1”); break;
case 10: System.out.print(“1”);
case 5: System.out.print(“1”);
default: System.out.print(“10”);
}
}
}

 

  1. a) 1
  2. b) 1110
  3. c) 11
  4. d) 10

Ans : b