In the UML notation, parameterized (generic) classes are represented by
the normal class representation with a dotted arrow pointing at the template parameter classes
the normal class representation but shaded grey.
the normal class representation with a dotted outline and the names of its parameter classes listed on the top right-hand corner.
the normal class representation with a rectangular box in its top left-hand corner.
Its a trick question - parameterized classes can't be specified in the UML notation.
XML is Case-Sensitive Language
True
False
Given: public static void before() { Set set = new TreeSet(); set.add("2"); set.add(3); set.add("1"); Iterator it = set.iterator(); while (it.hasNext()) System.out.print(it.next() + " "); } Which statements are true?
The before() method will print 1 2
The before() method will print 1 2 3
The before() method will print three numbers, but the order cannot be determined
The before() method will not compile
The before() method will throw an exception at runtime
Given: interface Hungry { void munch(E x); } interface Carnivore extends Hungry {} interface Herbivore extends Hungry {} abstract class Plant {} class Grass extends Plant {} abstract class Animal {} class Sheep extends Animal implements Herbivore { public void munch(Sheep x) {} } class Wolf extends Animal implements Carnivore { public void munch(Sheep x) {} } Which of the following changes (taken separately) would allow this code to compile? (Choose all that apply.)
Change the Carnivore interface to interface Carnivore extends Hungry {}
Change the Herbivore interface to interface Herbivore extends Hungry {}
Change the Sheep class to class Sheep extends Animal implements Herbivore { public void munch(Grass x) {} }
Change the Sheep class to class Sheep extends Plant implements Carnivore { public void munch(Wolf x) {} }
Change the Wolf class to class Wolf extends Animal implements Herbivore { public void munch(Grass x) {} }
No changes are necessary
Which collection class(es) allows you to grow or shrink its size and provides indexed access to its elements, but whose methods are not synchronized? (Choose all that apply.)
java.util.HashSet
java.util.LinkedHashSet
java.util.List
java.util.ArrayList
java.util.Vector
java.util.PriorityQueue
Given: public static void main(String[] args) { // INSERT DECLARATION HERE for (int i = 0; i <= 10; i++) { List row = new ArrayList(); for (int j = 0; j <= 10; j++) row.add(i * j); table.add(row); } for (List row : table) System.out.println(row); } Which statements could be inserted at // INSERT DECLARATION HERE to allow this code to compile and run? (Choose all that apply.)
List> table = new List>();
List> table = new ArrayList>();
List table = new List();
List table = new ArrayList();
Given: 3. import java.util.*; 4. class Business { } 5. class Hotel extends Business { } 6. class Inn extends Hotel { } 7. public class Travel { 8. ArrayList go() { 9. // insert code here 10. } 11. } Which, inserted independently at line 9, will compile? (Choose all that apply.)
return new ArrayList();
Which is true? (Choose all that apply.)
"X extends Y" is correct if and only if X is a class and Y is an interface
"X extends Y" is correct if and only if X is an interface and Y is a class
"X extends Y" is correct if X and Y are either both classes or both interfaces
"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces
Given: 3. class A { } 4. class B extends A { } 5. public class ComingThru { 6. static String s = "-"; 7. public static void main(String[] args) { 8. A[] aa = new A[2]; 9. B[] ba = new B[2]; 10. sifter(aa); 11. sifter(ba); 12. sifter(7); 13. System.out.println(s); 14. } 15. static void sifter(A[]... a2) { s += "1"; } 16. static void sifter(B[]... b1) { s += "2"; } 17. static void sifter(B[] b1) { s += "3"; } 18. static void sifter(Object o) { s += "4"; } 19. } What is the result?
-124
-134
-424
-434
-444
Compilation fails
Given: 3. public class Wind { 4. public static void main(String[] args) { 5. foreach: 6. for(int j=0; j<5; j++) { 7. for(int k=0; k< 3; k++) { 8. System.out.print(" " + j); 9. if(j==3 && k==1) break foreach; 10. if(j==0 || j==2) break; 11. } 12. } 13. } 14. } What is the result?
0 1 2 3
1 1 1 3 3
0 1 1 1 2 3 3
1 1 1 3 3 4 4 4
0 1 1 1 2 3 3 4 4 4