Core Java - Interview Questions and Answers for 'Generics' | 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

   



Core Java - Interview Questions and Answers for 'Generics' - 8 question(s) found - Order By Newest

 Q1. What are concepts introduced with Java 5 ?Core Java
Ans. Generics , Enums , Autoboxing , Annotations and Static Import.

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

   Like         Discuss         Correct / Improve     java   java5   generics   enum   autoboxing   annotations   static import        rare

Try 1 Question(s) Test


 Q2. Is this a valid initialization ? Explain.

Collection<Collection> collection = new LinkedList<LinkedList>();
Core Java
Ans. No. It will result in a type mismatch error.

Collection<Collection> collection = new LinkedList<Collection>();

is a valid initialization as collection being reference of "Collection" class can hold object of derived Class "LinkedList" due to runtime Polymorphism. Runtime polymorphism is not applicable to type arguments.

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

   Like         Discuss         Correct / Improve     generics  type argument


 Q3. Which of the following syntax is correct ?import static java.lang.System.*;or static import java.lang.System.*;Core Java
Ans. import static java.lang.System.*;

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

   Like         Discuss         Correct / Improve     java   static import   generics   import   OCJP   SCJP   Oracle certified java developer     Asked in 1 Companies


 Q4. Is it legal to initialize List like this ?


LinkedList l=new LinkedList();
Ans. No, Generic parameters cannot be primitives.

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

   Like         Discuss         Correct / Improve     java   collections   list   linkedlist   generics   yes-no


 Q5. Which of the following syntax are correct ?a. LinkedList<Integer> l=new LinkedList<int>();b. List<Integer> l=new LinkedList<int>();c. LinkedList<Integer> l=new LinkedList<Integer>();d. List<Integer> l = new LinkedList<Integer>();Core Java
Ans. All are correct.

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

   Like         Discuss         Correct / Improve     java   generics   linkedlist   list   collections      basic


Usually asked with Questions related to Generics.
 Q6. What are Type Erasures in Java ?Core Java
Ans. Type erasure applies to the use of generics. When generics are used, they're pre compiled into compile time checks and execution-time casts.

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

   Like         Discuss         Correct / Improve     type erasures  generics     Asked in 2 Companies      intermediate        rare


 Q7. Explain Generics in Java ?Core Java
Ans. Generics are a facility of generic programming that were added to the Java programming language in 2004 within J2SE5.0. They allow "a type or method to operate on objects of various types while providing compile-time type safety.

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

   Like         Discuss         Correct / Improve     generics     Asked in 7 Companies


 Q8. In case of generic class declared like following , What can T hold

class MyClass<T>{
T element;
}
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     generics



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: