Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java Support Interview Questions and Answers

Ques 1. What is the difference between an interface and an abstract class?

An abstract class can have both abstract and concrete methods, while an interface can only have abstract methods. In Java, a class can implement multiple interfaces but can extend only one abstract class.

Example:

Abstract class example:

abstract class Shape { 
  abstract void draw(); 
}

Interface example:

interface Shape { 
  void draw(); 
}

Is it helpful? Add Comment View Comments
 

Ques 2. Explain the concept of multithreading in Java.

Multithreading in Java allows multiple threads to execute concurrently. It improves the performance and responsiveness of a program. The 'Thread' class and 'Runnable' interface are commonly used to create and manage threads in Java.

Example:

Example:

class MyThread extends Thread { 
  public void run() { 
    // thread execution logic
  } 
}

MyThread t1 = new MyThread();
t1.start();

Is it helpful? Add Comment View Comments
 

Ques 3. What is the difference between '==', 'equals()', and 'hashCode()' methods in Java?

'==' is used to compare object references, 'equals()' is used to compare object content, and 'hashCode()' returns the hash code value of an object. It is recommended to override 'equals()' and 'hashCode()' when dealing with custom classes.

Example:

Example:

@Override
public boolean equals(Object obj) { 
  // custom implementation
}

@Override
public int hashCode() { 
  // custom implementation
}

Is it helpful? Add Comment View Comments
 

Ques 4. What is the purpose of the 'super' keyword in Java?

The 'super' keyword in Java is used to refer to the immediate parent class object. It is often used to call the parent class's methods, access its fields, and invoke the parent class's constructor.

Example:

Example:

class Subclass extends Superclass { 
  void display() { 
    super.display(); // calls the display method of the parent class
  } 
}

Is it helpful? Add Comment View Comments
 

Ques 5. Explain the 'try', 'catch', 'finally' blocks in Java Exception Handling.

'try' block contains the code that might throw an exception. 'catch' block handles the exception if it occurs. 'finally' block always executes, whether an exception is thrown or not. It is used for cleanup activities.

Example:

Example:

try { 
  // code that may throw an exception

catch (Exception e) { 
  // handle the exception

finally { 
  // cleanup code
}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook