Quizzes
Site Language: English
Українська
English
Русский
Programming Tests
Login
Sign Up
Programming Tests
Theory
Snippets
Papers
Landing
Android
Prices
FAQ
Cosmo Story
Terms and Conditions
Privacy Policy
Cookies Policy
Send Feedback
generics
:
Content language: English
Русский
What is the result of the following code execution? import java.util.Arrays; class Generic<T extends Number> { private T arr[] = {1, 2, 3, 4, 5}; public String toString(){ return Arrays.toString(arr); } } public class Test { public static void main(String [] args) { Generic<Double> obj = new Generic<Double>(); System.out.println(obj); } }
generics
Will the following code compile? public class GenericTest { public static void main(String[] args) { List<double> myList = new ArrayList<double>(); } }
generics
What will happen after compilation and execution of the following code? import java.util.*; public class Main { public static void main(String[] args) { try { ArrayList<Integer> ar = new ArrayList<Integer>(); List temp = ar; //1 temp.add(new java.util.Date()); //2 temp.add(new Float(1.66)); Iterator it = ar.iterator(); while (it.hasNext()) System.out.println(it.next()); System.out.println(ar.get(0)); } catch (Exception e) { System.out.println(e.getClass()); } } }
generics
In which lines the parameter T is not allowed to use (select 3 choices): public class Test & lt; T & gt; { private T item; // (1) private static T [] storage = new T [100]; // (2) public Test (T item) {this.item = item; } // (3) public T getItem () {return item; } // (4) public void setItem (T newItem) {item = newItem; } // (5) public static void getAllItems (T newItem) {// (6) T temp; // (7) } } </ code> </ pre>
generics
Which line in the code below will generate a compilation error? 01. public class Q11 { 02. public static void main(String[] args) { 03. List<? super Integer> one = new ArrayList<Integer>(); 04. addsome((List<? super Number>) one); 05. } 06. private static void addsome (List<? super Number> l){ 07. l.add(1); 08. Number num = 1; 09. l.add(num); 10. Object ob = 1; 11. l.add(ob); 12. l.add(null); 13. } 14. }
generics
What will be the output of the following code? package question; class HasF { public void f() { System.out.println("HasF.f()"); } } class Manipulators<T> { private T obj; public Manipulators(T x) { obj = x; } public void manipulation() { obj.f(); } } public class Manipulation { public static void main(String[] args) { HasF hf = new HasF(); Manipulators<HasF> manipul = new Manipulators<HasF>(hf); manipul.manipulation(); } }
generics
What will happen if you attempt to compile and run this code? import java.util.*; class A {} class B extends A {} class B1 extends A {} class B2 extends A {} class C1 extends B {} class C2 extends B {} public class AsListInt { public static void main(String[] args) { 1. List<A> list1 = Arrays.asList(new B(), new B1(), new B2()); 2. List<A> list2 = new ArrayList<A>(); 3. Collections.addAll(list2, new C1(), new C2()); 4. List<A> list3 = Arrays.asList(new C1(), new C2()); } }
generics
What happens after the compilation and execution of following code? import java.util.*; public class X { public <X> X(X x) { System.out.println("generic constructor"); } public X(X x) { System.out.println("simple constructor"); } public X() { } public static void main(String args[]) { X x = new X(new Integer(5)); X x1 = new X(x); } }
generics
What will be the output of the following code? public class Test<M> { <M> Class getArgumentClass(M m) { return m.getClass(); } public static void main(String[] args) { Test test = new Test(); Double d = new Double(12); Class c1 = test.<Double>getArgumentClass(d); Class c2 = test.<Number>getArgumentClass(d); Class c3 = test.getArgumentClass(d); System.out.println(c1 == c2); System.out.println(c1 == c3); System.out.println(c2 == c3); } }
generics
Which of the following options could be inserted into (1) without causing compilation error import java.util.*; public class Test { public static void main(String[] args) { List<?> lst = new ArrayList<String>(); // (1) Insert code here } }
generics
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes