What changes are needed to make the following program compile?
import java.util.*; public class Main { public static void main(String args[]) { String s1 = "abc"; String s2 = "def"; Vector v = new Vector(); v.add(s1);// w ww. ja v a2 s. c o m v.add(s2); String s3 = v.elementAt(0) + v.elementAt(1); System.out.println(s3); } }
v.elementAt(0)
to a String. v.elementAt(1)
to an Object. B.
The elementAt()
method of Vector returns an Object reference.