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);
System.out.println(buff.toString());
}
}
What will be the output of the following?
1. Welcome
2. Compile error
3. java.lang.ClassCastException
4. null
(3)
'java.lang.String' cannot be cast to 'java.lang.StringBuffer'
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.