Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java Support Interview Questions and Answers

Ques 11. What is the difference between 'throw' and 'throws' in Java?

'throw' is used to explicitly throw an exception, while 'throws' is used in method signatures to declare the exceptions that the method might throw. Multiple exceptions can be declared using a comma-separated list in 'throws'.

Example:

Example:

void myMethod() throws CustomException { 
  // method implementation
}

Is it helpful? Add Comment View Comments
 

Ques 12. What is the purpose of the 'transient' keyword in Java?

'transient' is used to indicate that a variable should not be serialized during object serialization. The value of a transient variable is not persisted when the object is stored.

Example:

Example:

class MyClass implements Serializable { 
  transient int sensitiveData; 
}

Is it helpful? Add Comment View Comments
 

Ques 13. Explain the 'instanceof' operator in Java.

The 'instanceof' operator is used to test if an object is an instance of a particular class or interface. It returns a boolean value: 'true' if the object is an instance, and 'false' otherwise.

Example:

Example:

if (myObject instanceof MyClass) { 
  // do something
}

Is it helpful? Add Comment View Comments
 

Ques 14. What is the purpose of the 'break' statement in Java?

The 'break' statement is used to terminate the loop or switch statement. It is often used to exit a loop prematurely when a certain condition is met.

Example:

Example:

for (int i = 0; i < 10; i++) { 
  if (i == 5) { 
    break; // exit the loop when i is 5
  } 
}

Is it helpful? Add Comment View Comments
 

Ques 15. Explain the concept of method overriding in Java.

Method overriding allows a subclass to provide a specific implementation of a method that is already defined in its superclass. The overridden method in the subclass should have the same signature (name, return type, and parameters).

Example:

Example:

class Animal { 
  void makeSound() { 
    System.out.println('Generic Animal Sound'); 
  } 
}

class Dog extends Animal { 
  void makeSound() { 
    System.out.println('Bark'); 
  } 
}

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2025 WithoutBook