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 will be the result of compilation of the following code? public class GenericClassReferences { public static void main(String[] args) { Class intClass = int.class; Class<Integer> genericIntClass = int.class; // 1 genericIntClass = Integer.class; // 2 intClass = double.class; // 3 genericIntClass = double.class; // 4 } }
generics
What will be the result of compilation and execution of the following code? import java.util.*; class AClass { } public class Test { public static void main (String... args) { ArrayList<AClass> a = new ArrayList<AClass>(); AClass aaaClass = new AClass(); a.add(aaaClass); staticMethod1(a); staticMethod2(a); System.out.println(a.size()); } static <T super ArrayList<AClass>> void staticMethod1(T a) { // 1 AClass c = new AClass(); a.add(c); } static <T extends ArrayList<AClass>> void staticMethod2(T a) { // 2 AClass c = new AClass(); a.add(c); } }
generics
What will be the result of compilation and execution of the following code: package X; public class X<X> { X x; public X(){ } public X(X x){ this.x=x; } public <Y extends X> Y Y(Y y){ return y; } } class Y<Y extends X> extends X{ private static Integer Y = 5; public static void main(String...X){ System.out.print(new X().Y(Y).toString()); } }
generics
Choose the correct result of compiling and running the following code: import java.util.*; class Generics13 { public static void main(String[] args) { List<Integer> list = new LinkedList<Integer>(); list.add(1); list.add(4); list.add(-4); for(Iterator i = list.iterator(); i.hasNext();) { Integer in = i.next(); System.out.println(in); } } }
generics
What will be the result of compilation and execution of the following code? public class Test<T>{ static class MyTest{ public MyTest(int k) { System.out.println("MyTest created"); } } T obj1, obj2; public Test(T t, Class<T> cls) throws Exception { obj1 = t; // 1 obj2 = cls.newInstance(); // 2 } public static void main(String[] args) throws Exception { MyTest mt = new MyTest(10); Test t = new Test(mt, MyTest.class); } }
generics
What is the result of compilation and execution of the following code? public class Test { public static void main(String[] args) { List<Integer> list = new ArrayList<Integer>(); list.add(100); list.add(200); list.add(300); list.add(200); Set<Number> set = new HashSet<Integer>(list); System.out.println(set.size()); } }
generics
What is the result of compilation and execution of the following program: import java.util.*; class Main { public static void main(String[] args) { List<?> list = new ArrayList<String>(); list.add("a"); System.out.println(list.get(0)); } }
generics
← Prev
1
2
Next →
Sign Up Now
or
Subscribe for future quizzes