Restrictions On Generics

1

What is the output of this program?

  
    import java.util.*;
    public class genericstack  {
        Stack  stk = new Stack ();
	public void push(E obj) {
            stk.push(obj);
	}
	public E pop() {
            E obj = stk.pop();
	    return obj;
	}
    }
    class Output {
        public static void main(String args[]) {
            genericstack  gs = new genericstack();
            gs.push(36);
            System.out.println(gs.pop());
        }
    }
A. H
B. Hello
C. Runtime Error
D. Compilation Error

2

What is the output of this program?

 
    import java.util.*;
    class Output {
        public static void addNumbers(List list) {
            for (int i = 1; i <= 10; i++) {
                list.add(i);
            }
        }
        public static void main(String args[]) {
           List ld = Arrays.asList();
           addnumbers(10.4);
           System.out.println("getList(2)");
        }
    }

A. 1
B. 2
C. 3
D. 6

3

What is the output of this program?

    import java.util.*;
    class Output {
        public static double sumOfList(List list) {
            double s = 0.0;
            for (Number n : list)
                s += n.doubleValue();
            return s;
        }
        public static void main(String args[]) {
           List ld = Arrays.asList(1.2, 2.3, 3.5);
           System.out.println(sumOfList(ld));
        }
    }
A. 5.0
B. 7.0
C. 8.0
D. 6.0

4

What is the output of this program?

 
    import java.util.*;
    public class genericstack  {
        Stack  stk = new Stack ();
	public void push(E obj) {
            stk.push(obj);
	}
	public E pop() {
            E obj = stk.pop();
	    return obj;
	}
    }
    class Output {
        public static void main(String args[]) {
            genericstack  gs = new genericstack();
            gs.push("Hello");
            System.out.print(gs.pop() + " ");
            genericstack  gs = new genericstack();
            gs.push(36);
            System.out.println(gs.pop());
        }
    }
A. Error
B. Hello
C. 36
D. Hello 36

5

Which of the following cannot be Type parameterized?

A. Oveloaded Methods
B. Generic methods
C. Class methods
D. Overriding methods