Core Java - Interview Questions and Answers for 'Interface' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   next 30
 Q31. Will it create any problem if We add elements with key as user defined object into the TreeMap ?
Ans. It won't create any problem if the objects are comparable i.e we have that class implementing Comparable interface.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   treemap   comparable interface


 Q32. Can we access Interface static method using Interface references ?
Ans. No, only using Interface Name.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java8   static interface methods


 Q33. Can we have default method with same name and signature in the derived Interface as the static method in base Interface and vice versa ?
Ans. Yes , we can do that as static methods are not accessible using references and hence cannot lead to conflict. We cannot do inverse as Default methods cannot be overridden with the static methods in derived interface.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java8   default methods   static interface methods


 Q34. What is Closeable ?Core Java
Ans. A Closeable is an interface which is a source or destination of data that can be closed.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     closeable   interfaces      intermediate        rare


Not frequently asked as it was introduced with Java 8.
 Q35. What is the @FunctionalInterface annotation ?Core Java
Ans. This is an informative annotation that specify that the interface is a functional interface. A Function Interface has only one abstract method and many default methods. Compiler generates an error if the interface specified with the annotation doesn't abide by the specifications for functional interface.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   java8   java 8   functional interface   default methods


 Q36. Name few interfaces that extends Collection Interface ?
Ans. http://www.buggybread.com/2015/02/java-collections-interfaces-that.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   collection interface


 Q37. Name few classes that implement Collection interface ?
Ans. http://www.buggybread.com/2015/02/java-collections-classes-that-implement.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   collections   collection interface


 Q38. Is it correct to say that Interfaces are abstract data types ?
Ans. No.

Data Type holds data whereas Interface doesn't hold anything. Interface is a contract about how to communicate with the underlying Class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   interface   data type


 Q39. What is the package name for CertStoreParameters class?
Ans. java.lang

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces   java   CertStoreParameters   include


 Q40. Which is the Parent Class of CertStoreParameters class?
Ans. Clonable

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces   java   CertStoreParameters   include


 Q41. Variables of an interface are intrinsically ...

a. transient
b. final
c. public
d. static
Ans. b,c and d i.e final , public and static

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   interface   interface variables


 Q42. Which is the Parent Class of CertStoreParameters class?
Ans. Clonable

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces   java   CertStoreParameters   include


 Q43. In the following code , how many methods needs to be implemented in Class B ?

public interface A{
   public void method1();
   public void method2();
   public void method3();
}

abstract class B implements A{
}
Core Java
Ans. As Class B has been declared abstract , we can either implement any of these methods and just declare rest of them abstract.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces  abstract classes  code  coding

Try 2 Question(s) Test


Frequently asked.
 Q44. What should a class do if its implementing an interface ?Core Java
Ans. It should either implement all interface methods or declare unimplemented methods as abstract.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces     Asked in 1 Companies      Basic        frequent

Try 1 Question(s) Test


 Q45. Does default methods introduce multiple inheritance and the Diamond problem in Java 8 ?Core Java
Ans. Default methods results in multiple inheritance of behavior and not of state. In case we try to implement multiple interfaces with default method having same name and signature, and don't override it in implementation class, it will throw an error.

For example -

interface MyInterface {
public void default myMethod(){
}
}

interface MyInterface2 {
public void default myMethod(){
}
}

class MyClass implements MyInterface,MyInterface2 {
}

This code will compilation error "Duplicate Default Method"

if we specify the definition of myMethod() in myClass, compiler won't complain and there is no conflict and MyClass can use overridden definition. But if we don't override myMethod() in MyClass, Java would be in conflict as to what definition should be carried to MyClass and hence throws compilation error.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     default methods  java 8  multiple inheritance  object oriented programming (oops)  oops concepts  diamond problem   interfaces


 Q46. Do we need to implement all interface methods if a class is implementing it ?Core Java
Ans. Yes, a Class is supposed to define all abstract methods declared in the interface. With Java 8 , Interfaces can have default methods which need not be implemented by the implementing class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces


 Q47. Where do we generally use comparable interface ?Core Java
Ans. Implementing Comparable interface means that the elements of the class are comparable i.e the class provides the implementation of compareTo method that would help comparing the elements.

This is usually required if we are planning to sort elements of a collection, If compareTo method is not defined , the sorting class / method could never understand a way to compare its elements in order to sort them.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     comparable interface

Try 1 Question(s) Test


 Q48. Why Collection interface does not extend Cloneable interface ?Core Java
Ans. Here is the list of classes that implements Collections Interface - http://www.buggybread.com/2015/02/java-collections-classes-that-implement.html

Having Collection interface to extend Cloneable interface would mean necessarily implement clone method by all implementing classes. As not all collection classes allow duplicate elements, it makes no sense to clone elements for them.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     cloneable  collections  collection interface  cloning


 Q49. Which is the root interface of Collection classes in Java ?Core Java
Ans. java.util.Collection

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collection interface  collections


 Q50. Can we have an inner class within Interface ?Core Java
Ans. Yes, we can define an inner class within interface.Inside the interface, the inner class is implicitly public static.

So the following is legit in Java

public interface BuggyBreadInterface {
   void doSomething();

   public class BuggyBreadClass implements BuggyBreadInterface{
      void doSomething(){
         System.out.println("Do something");
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  inner class in interface  nested classes


 Q51. What is nested interface?Core Java
Ans. Interface that is declared inside the interface or class, is known as nested interface. It is static by default.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interface  nested interface      intermediate

Try 1 Question(s) Test


 Q52. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
   public static void main(String[] args){
      System.out.println(BaseInterface.i);
   }
}

What will be the output upon executing main and Why ?
Core Java
Ans. It will print 4 because member elements of an interface are implicitly static and hence the concept of overriding doesn't work.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces  coding  code  extending interfaces  diamond interfaces     Asked in 1 Companies      intermediate


 Q53. What will be the output of following code ?

Base Interface

public interface BaseInterface {
   int i = 4;
}

Derived Interfaces

public interface DerivedInterface1 extends BaseInterface{
   int i = 5;
}

public interface DerivedInterface2 extends BaseInterface{
   int i=6;
}

Implementing Class

public class Class implements DerivedInterface1,DerivedInterface2 {
int i=10;   

public static void main(String[] args){
      System.out.println(new Class().i);
   }
}

What will be the output upon executing main and Why ?
Core Java
Ans. 10

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces  coding  code      intermediate


 Q54. What are the types of Executor Interfaces ?Core Java
Ans. Executor - Simple Interface that supports launching new tasks.

ExecutorService - Subinterface of Executor, which adds features that help manage the lifecycle, both of the individual tasks and of the Executor itself.

ScheduledExecutorService - Subinterface of ExecutorService, supports future and-or periodic execution of tasks.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Executor Interfaces     Asked in 1 Companies


 Q55. What are the core interfaces in Hibernate?Hibernate
Ans. Session,SessionFactory,Configuration,Transaction,query and Criteria

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     core interfaces of Hibernate     Asked in 1 Companies        frequent

Try 1 Question(s) Test


 Q56. What are the core interfaces of Spring mvc ?Spring
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     core interfaces of Spring mvc


 Q57. Can an interface be defined inside a class just like we can have inner classes inside a class ?Core Java
Ans. Yes , we can have an interface that is part of a class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes   inner interface  nested classes


 Q58. Can an interface implements another interface ?Core Java
Ans. No. No interface provides any implementation and hence the declaration isn't viable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interface      basic


 Q59. What are the advantage of Abstract classes over interfaces with respect to Java 7 ? and What changed in Java 8 to help facilitate that in Java 8 ?Core Java
Ans. Abstract Classes provide default implementations of methods that are inherited by the classes that extend them, which was not the case for Interfaces. This changed in Java 8, where default implementations are provided for methods.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     abstract classes  interfaces  default method     Asked in 1 Companies      expert


 Q60. Why do we use Thread Class as well as Runnable Interface for creating threads in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Threads  Thread class  runnable interface


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: