Share on Google+Share on Google+

SCJP Module-9 Question-9

The program given below will check your understanding NavigableSet, List, ArrayList and TreeSet of collection framework in Java.

Given below the sample code :

public class Check{
public static void main(String args[]){
ArrayList alist = new ArrayList();
ArrayList<String> listStr = alist;
ArrayList<StringBuffer> listBuf = alist;
listStr.add(0, "Welcome");
StringBuffer buff = listBuf.get(0);

What will be the output of the following?

1. Welcome
2. Compile error
3. java.lang.ClassCastException
4. null




'java.lang.String' cannot be cast to 'java.lang.StringBuffer'


Posted on: July 16, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.