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 Rating

   
 Q41. What is a cloneable interface and what all methods does it contain?Core Java
Ans. Cloneable is a declaration that the class implementing it allows cloning or bitwise copy of it's object state. It is not having any method because it is a MARKER interface.

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

   Like         Discuss         Correct / Improve     java   oops   cloneable   marker interface  cloning     Asked in 2 Companies


  Q42. What is Comparable Interface?Core Java
Ans. It is used to sort collections and arrays of objects using the collections.sort() and java.utils. The objects of the class implementing the Comparable interface can be ordered.

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

   Like         Discuss         Correct / Improve     java   collections   comparable interface     Asked in 7 Companies      intermediate        frequent

Try 1 Question(s) Test


 Q43. Explain Set Interface?Core Java
Ans. It is a collection of element which cannot contain duplicate elements. The Set interface contains only methods inherited from Collection and adds the restriction that duplicate elements are prohibited.

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

   Like         Discuss         Correct / Improve     java   collections   set interface   set


 Q44. What is Externalizable interface?Core Java
Ans. Externalizable is an interface which contains two methods readExternal and writeExternal. These methods give you a control over the serialization mechanism.

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

   Like         Discuss         Correct / Improve     java   serialization   externalizable interface     Asked in 2 Companies      intermediate        rare


 Q45. What is an enumeration?Core Java
Ans. An enumeration is an interface containing methods for accessing the underlying data structure from which the enumeration is obtained. It allows sequential access to all the elements stored in the collection.

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

   Like         Discuss         Correct / Improve     java   enum   enumeration interface   basic interview question

Try 2 Question(s) Test


 Q46. How TreeMap orders the elements if the Key is a String ?
Ans. As String implements Comparable, It refers to the String compareTo method to identify the order relationship among those elements.

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

   Like         Discuss         Correct / Improve     java   collections   comparable interface   treemap   compareto


 Q47. Can we add heterogeneous elements into TreeMap ?
Ans. No, Sorted collections don't allow addition of heterogeneous elements as they are not comparable.

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

   Like         Discuss         Correct / Improve     java   collections   comparable interface   treemap


 Q48. 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


 Q49. Can we use static method definitions in Interfaces ?Core Java
Ans. Yes, Effective Java 8.

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

   Like         Discuss         Correct / Improve     java   java8   static interface methods   yes-no     Asked in 1 Companies


 Q50. 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


 Q51. 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


 Q52. 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.
 Q53. 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


 Q54. How is Abstraction implemented in Java ?Core Java
Ans. Abstraction is provided in Java by following ways -

Coding to the ( Interfaces / Abstract Classes ) or contracts

By Encapsulating details within classes and exposing the minimal Door ( few public methods )

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

   Like         Discuss         Correct / Improve     java   oops concepts   abstraction   interfaces   abstract class   encapsulation  object oriented programming (oops)  oops concepts     Asked in 3 Companies      basic        frequent


 Q55. 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


 Q56. 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


Very Frequently asked. Have been asked in HCL Technologies very frequently ( based on 3 feedback ). Among first few questions in many interviews.
  Q57. Differences between abstract class and interface ?Core Java
Ans. Abstract classes can have both abstract methods ( method declarations ) as well as concrete methods ( inherited to the derived classes ) whereas Interfaces can only have abstract methods ( method declarations ).

A class can extend single abstract class whereas it can implement multiple interfaces.

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

   Like         Discuss         Correct / Improve     java   classes   abstract class   interfaces   abstract class vs interface   abstract classes vs interfaces     Asked in 82 Companies      basic        frequent


 Q58. What is the use of runnable interface if we can always create a new thread using Thread class ?Core Java
Ans. It's a choice to be made whether to use first approach ( Thread class ) or second approach ( runnable interface ) by the programmer. The second facility has been given for cases where your class is already extending some parent class and hence cannot extend another class ( for Thread ) as Java doesn't allow multiple inheritance.

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

   Like         Discuss         Correct / Improve     java   threads   multithreading   runnable interface  concurrency


 Q59. Why do we need Thread class even in case we execute thread using runnable interface ?Core Java
Ans. Thread class holds the definition of start method ( This is the method that starts execution of new thread and then calls run method within the scope of new thread ). Interfaces don't hold any definition and so does runnable. So it makes it necessary the usage of Thread class , whatever implementation you choose.

When your class extends the thread class, it carries the definition of start method from parent Thread class onto itself and hence new yourClass.start() helps starting a new thread and then executing run method in that new thread scope.

When you implement runnable interface , you are just making it sure to the JVM that you have implemented the required method ( run() ) which the Thread start method will look for upon executing start method.

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

   Like         Discuss         Correct / Improve     java   threads   multithreading   runnable interface   thread class


 Q60. 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


 Q61. 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


 Q62. 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


 Q63. Interface can only have ...

a. Member elements and Methods.
b. Static Variables and Static Methods.
c. Static Final Variables and Instance Method Declarations.
d. Member Elements , Instance Methods, Static variables and Static Methods.
Ans. Static Final Variables and Instance Method Declarations.

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

   Like         Discuss         Correct / Improve     java   oops   interfaces


 Q64. 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


 Q65. Which of the following doesn't extend Collection interface ?

a. Set
b. List
c. Map
d. Queue
Core Java
Ans. Map

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

   Like         Discuss         Correct / Improve     java   collections   collection interface


 Q66. 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


 Q67. 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.
 Q68. 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


 Q69. Which method needs to be implemented if a class is implementing comparable interface ?Core Java
a. comp
b. compare
c. compareTo
d. compareEquals

Ans.c. compareTo

 Q70. If X implements Y and Y extends Z, Which of the following initialization is correct ?Core Java
a. X x = new Y();
b. X x = new Z();
c. Z z = new Y();
d. Z z = new X();

Ans.d. Z z = new X();

previous 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: