51. What will be the output of the following Java program?
import java.util.*;
class Output
{
public static double sumOfList(List<? extends Number> list)
{
double s = 0.0;
for (Number n : list)
s += n.doubleValue();
return s;
}
public static void main(String args[])
{
List<Double> ld = Arrays.asList(1.2, 2.3, 3.5);
System.out.println(sumOfList(ld));
}
}
import java.util.*;
class Output
{
public static double sumOfList(List<? extends Number> list)
{
double s = 0.0;
for (Number n : list)
s += n.doubleValue();
return s;
}
public static void main(String args[])
{
List<Double> ld = Arrays.asList(1.2, 2.3, 3.5);
System.out.println(sumOfList(ld));
}
}
52. What will be the output of the following Java program?
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
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 <Integer> gs = new genericstack<Integer>();
gs.push(36);
System.out.println(gs.pop());
}
}
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
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 <Integer> gs = new genericstack<Integer>();
gs.push(36);
System.out.println(gs.pop());
}
}
53. Which of the following allows us to call generic methods as a normal method?
54. What will be the output of the following Java program?
import java.util.*;
public class genericstack <E>
{
Stack stk = new Stack <E>();
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 <String> gs = new genericstack();
gs.push("Hello");
System.out.println(gs.pop());
}
}
import java.util.*;
public class genericstack <E>
{
Stack stk = new Stack <E>();
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 <String> gs = new genericstack();
gs.push("Hello");
System.out.println(gs.pop());
}
}
55. Which of these type parameters is used for a generic methods to return and accept any type of object?
56. Which of the following keywords are used for lower bounding a wild card?
57. What will be the output of the following Java program?
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
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 <Integer> gs = new genericstack<Integer>();
gs.push(36);
System.out.println(gs.pop());
}
}
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
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 <Integer> gs = new genericstack<Integer>();
gs.push(36);
System.out.println(gs.pop());
}
}
58. What is use of wildcards?
59. Which of these types cannot be used to initiate a generic type?
60. What will be the output of the following Java code?
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
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 <String> gs = new genericstack<String>();
gs.push("Hello");
System.out.println(gs.pop());
}
}
import java.util.*;
public class genericstack <E>
{
Stack <E> stk = new Stack <E>();
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 <String> gs = new genericstack<String>();
gs.push("Hello");
System.out.println(gs.pop());
}
}