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?
- a) Compile time error
- b) Run time error
- c) Checked Exception
- d) Un checked exception
Ans : a
Question 2
Which language is platform independent?
- a) PHP
- b) HTML
- c) Java
- d) .Net
Ans : c
Question 3
How to define method overriding?
- a) Method overriding is the concept of declaring method with same name in same class.
- b) If a method with same return type and name is declared in child class then its called method overriding.
- c) If a method with same name with different return type and different number of parameters in child class then its called method overriding.
- d) All of the above.
Ans : b
Question 4
Abstraction can be achieved with?
- a) inheritance
- b) Multiple Inheritance
- c) Abstraction classes
- d) Interface and abstract classes
Ans : d
Question 5
In what case an exception is thrown even the code is wrapped with try/catch?
- a) Exception occurred inside catch block.
- b) Exception occurred in try block.
- c) Compile time error occurred in main method
- d) Null pointer exception occurred in finally.
Ans : a
Question 6
How many instance a singleton class can have?
- a) Any numbers
- b) Only one
- c) Depends on number of constructor
- d) 7
Ans : b
Question 7
Which method is called if main is not a static?
- a) static block whichever is on top of the class
- b) Throws NoSuchMethodError
- c) Calls main method even it’s not static
- d) Runs all static methods and skip main method
Ans : b
Question 8
Can a class named “Question” can have constructor with different name?
- a) Yes, If the method is called from the constructor then it will act as a constructor
- b) Yes if it is same as parent class name
- c) Yes, if it defined as static final
- d) No it’s not possible
Ans : d
Question 9
How many ways are there to create an object in java?
- a) 1
- b) 3
- c) 4
- d) 2
Ans : c
Question 10
Which of following class is not a part of java.util.concurrent package?
- a) Callable
- b) ExecutorService
- c) CompletionServices
- d) Executors
Ans : c
Question 11
Which version of java introduced Lambda expressions?
- a) Java 8
- b) Java 6
- c) Java 9
- 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?
- a) Pass by reference
- b) Pass by value
- c) It’s both depends on the coding
- 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?
- a) Read Only class
- b) POJO
- c) Write only class
- d) Immutable class
Ans : d
Question 14
What is it called if all nodes are covered with minimum number of edges?
- a) Linked list
- b) Hashmap
- c) Spanning tree
- d) Arraylist
Ans : c
Question 15
Can we access private method outside the class?
- a) Yes
- b) No
- c) Only possible in C++
- d) Accessing it will cause run time error.
Ans : a
Question 16
What comes under polymorphism?
- a) Abstraction
- b) Inheritance
- c) Java
- 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?
- a) Implementation class will also have 3 methods
- b) Implementation class can have either less than or more than 3 but it can’t be 3.
- c) It can have more than 3 methods, but minimum 3 are required.
- d) Implementation is not required for compilation.
Ans : c
Question 18
What are local classes?
- a) There is nothing like local classes in java.
- b) It is a class which is private.
- c) Any class which is defined inside a block of the code and it’s can’t be access outside the block.
- d) Wrapper classes are called as local.
Ans : c
Question 19
Which block gives guarantee to execute the code?
- a) finally
- b) try
- c) catch
- 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?
- a) Whatever comes first
- b) Only the one which is given in entry point class
- c) Throws error
- 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){ |
- a) First
- b) Second
- c) Compile time error
- 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){ for(int i=2; i<variable1; i++){ |
- a) 234
- b) 0123
- c) 123
- 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){ |
- a) Compile time error
- b) 2593
- c) 93
- 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){ if(variable1==10) if(variable1!=9) |
- a) 20101110
- b) 2010
- c) 201011
- 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){ switch(variable1){ |
- a) 1
- b) 1110
- c) 11
- d) 10
Ans : b
Leave a comment