Tricky Java Interview Questions Series: Release 1

Abhijit Jadhav
2 min readJul 12, 2022

Hello readers I am back with a java interview questions series. We will be covering the tricky Java Interview Questions asked in the interview. These questions are truly based on the interview experience of me and some of my colleagues. We will not be covering the simple questions here that are easily available on different websites. We will only be covering questions that will need a deep understanding of the concepts.

Our main aim for this series is to get you a quick revision or practice before the interview. So you can read the question and try to answer them. If you are stuck don't worry you can always google the answer. Stay tuned for new questions.

Photo by Amy Hirschi on Unsplash

Also, we will only cover answers wherever possible but not for all scenarios.

  1. Identify the output of the below code:
class ABC {
static {
System.out.println("static block of ABC");
}
public static void display() {
System.out.println("static method class ABC");
}
public ABC() {
System.out.println("No parameterized constructor ABC");
}

public ABC(int a) {
System.out.println("Parameterized constructor ABC " + a);
}
}
class CDE extends ABC {
static {
System.out.println("static block CDE");
}

public static void display() {
System.out.println("static method class CDE");
}

public CDE() {
System.out.println("No parameterized constructor CDE");
}
public CDE(int a) {
System.out.println("Parameterized constructor CDE");
}
}
public class Interview {
public static void main(String[] args) {
ABC abc = new CDE(1);
// ABC abc = new CDE();
// ABC abc = new ABC(1);
// CDE cde = new CDE(1);
}
}

OUTPUT:

static block of ABCstatic block CDENo parameterized constructor ABCParameterized constructor CDE

2. What is the difference between Runnable and Callable interfaces?

3. What are the scenarios where you will use the Abstract Class and Interface ?

4. In the Spring security implementation what will happen if you receive a fake or invalid token?

5. Can we override the static method and if so then how?

6. Can we run a program without the main method?

7. If we have an interface of Hardisk and two classes Samsung and Lenevo implements the interface then how will we inject the dependency into the other Laptop class?

8. What is the real-life use case of the Builder Design pattern?

9. Suppose you want to connect to MySQL and MongoDB at the same time and in the same application then how will you achieve this? Which design pattern you will go for and Why?

10. What will be your approach for migrating a monolithic architecture to microservice architecture?

You can read Release 2 here

--

--

Abhijit Jadhav

Full Stack Java Developer and AI Enthusiast loves to build scalable application with latest tech stack