Make your own free website on Tripod.com
1- 
import java.util.*;

class GenDemo1 {
	public static void main(String... args) {
		List<? super String> list1 = new ArrayList<Object>();
		list1.add(new String());	//Line 1
		list1.add(new Object());	//Line 2			
	}

}

2-

import java.util.*;

class Person implements Comparable<Person> {
	String name;
	Person() {}
	Person(String name) {this.name =name;}
	public int compareTo(Person p1) {
		return name.compareTo(p1.name);
	}
}

class Manager extends Person {
}

//Insert code here

	public void add(T item) {
	}

}

class GenDemo2 {
	public static void main(String... args) {
		MyList<Person> list1 = new MyList<Person>();
		MyList<Manager> list2 = new MyList<Person>();
									
	}
}
What inserted independently at the marked location will allow the code to compile and run well.
(Choose all that apply)


A- class MyList<T extends Comparable<T>> {
B- class MyList<T extends Comparable> {
C- class MyList<T extends Comparable<? super T>> {
D- class MyList<T extends Comparable<? extends T>> {
E- class MyList<T> {
F- class MyList<?> {
G- class MyList<? extends Comparable> {
H- class MyList<T extends Comparable<?> {

3-

1. import java.util.*;
2. public class Fruits {
3. public static void main(String [] args) {
4. Set c1 = new TreeSet();
5. Set o1 = new TreeSet();
6. bite(c1);
7. bite(o1);
8. }
9. // insert code here
10. }
11. class Citrus { }
12. class Orange extends Citrus { }

Which, inserted independently at line 9, will compile? (Choose all that apply.)

A: static void bite(Set<?> st1){}
B: static void bite(Set<? extends Citrus> st1){}	
C: static void bite(Set<? extends Orange> st1){}
D: static void bite(Set<Object> st1){}
E: static void bite(Set<? extends Object> st1){}
F: static void bite(Set<? extends Fruits> st1){}
G: public static void bite(Set<Object> s) { }



4- 
1. import java.util.*;
2. public class Fruits {
3. public static void main(String [] args) {
4. Set<Citrus> c1 = new TreeSet();
5. Set<Citrus> o1 = new TreeSet();
6. bite(c1);
7. bite(o1);
8. }
9. // insert code here
10. }
11. class Citrus { }
12. class Orange extends Citrus { }

Which, inserted independently at line 9, will compile? (Choose all that apply.)

A: static void bite(Set<Citrus> st1){}
B: static void bite(Set<? super Citrus> st1){}
C: static void bite(Set<? extends java.io.Serializable> st1){}
D: public static void bite(Set<Object> s) { }
E: static void bite(Set<? extends Comparable> st1){}
F: static void bite(Collection col){}
G: static void bite(Collection<? extends Citrus> st1){}
H: static void bite(Object st1){}

5-

import java.util.*;

public class DemoGen {
	public static void main(String... args) {
		List<? extends Number> list1 = new ArrayList<Integer>();	//Line1
		list1.add(new Integer(10));	//Line 2
	}

}
A: Compilation fails at line 1 
B: Compilation fails at line 2
C: Compiles and runs fins
D: Compiles but run time exception


6- 
import java.util.*;

public class DemoGen {
	public static void main(String... args) {
		List<? super Number> list1 = new ArrayList<Object>();	//Line 1
		list1.add(new Integer(10));	//Line 2
		list1.add(12); //Line 3
		list1.add(120.01f); //Line 4
		
	}
}

A: Compilation fails at line 3
B: Compilation fails at line 4
C: Multiple compile error
D: Compiles and runs fins
E: Compiles but run time exception

7- 
import java.util.*;
public class DemoGen {
	public static void main(String... args) {
		List list1 = new ArrayList<Integer>(); //Line 1
		list1.add(12);
		list1.add(13);
		list1.add(14);
		list1.add(15);

		for(Integer x : list1) {
			System.out.print(x + ",");
		}		
	}
}
A: Prints 12,13,14,15
B: Compilation fails due to error at Line 1
C: Comlilation fails
D: Compiles but run time exception
E: None of the above

8-
import java.util.*;
public class DemoGen {
	public static void main(String... args) {
		Set list = new TreeSet<Integer>(); //Line 1
			
		list1.add(15);
		list1.add(12);
		list1.add(new String("13e")); //Line 2
		list1.add(14);
		
		
		for(Integer x : list1) {	// Line 3
			System.out.print(x + ",");
		}
		
	}
}

A: Compilation fails due to error at Line 1
B: Compilation fails due to error at Line 2
B: Compilation fails due to error at Line 3
C: Line 1 and Line 2 cause compilation error
D: Compiles fine but run time exception
E: Compiles and runs fine and prints 12,13,14,15

9-
import java.util.*;
public class DemoGen {
	public static void main(String... args) {
		Set<Integer> list = new TreeSet(); //Line 1
			
		list1.add(14);
		list1.add(15);
		list1.add(12);
		list1.add(new Integer("13")); //Line 2
		
		
		
		for(Integer x : list1) {	// Line 3
			System.out.print(x + ",");
		}
		
	}
}

A: Compilation fails due to error at Line 1
B: Compilation fails due to error at Line 2
B: Compilation fails due to error at Line 3
C: Line 1 and Line 2 cause compilation error
D: Compiles fine but run time exception
E: Compiles and runs fine and prints 12,13,14,15

10- 
import java.util.*;
public class DemoGen {
	public static void main(String... args) {
		Set list = new TreeSet(); //Line 1
			
		list1.add(14.12f);
		list1.add(15.01);
		list1.add(1.21);
		list1.add(new Integer("13")); //Line 2
		
		
		
		for(Object x : list1) {	// Line 3
			System.out.print(x + ",");
		}
		
	}
}

A: Compilation fails due to error at Line 1
B: Compilation fails due to error at Line 2
B: Compilation fails due to error at Line 3
C: Line 1 and Line 2 cause compilation error
D: Compiles fine but run time exception
E: Compiles and runs fine and prints 12,13,14,15

11-
public class Employee implements Comparable { 
String name;
	private Employee(String name){
		this.name = name;
	}
	
	public int compareTo(Employee e1) {
		return name.compareTo(e1.name);
	}
}

A: Compiles fine 
B: Compiler error due to failing contract of interface implementation
C: Compiler error because constructor can't be private 
C: compiler error because public class must have a main() method to compile the code
D: Compiles with an exception