Questions no -3
What is the output for the below code ?
public class Test {
public static void main(String argv[]){
ArrayList list = new ArrayList();
ArrayList listStr = list;
ArrayList listBuf = list;
listStr.add(0, "Hello");
StringBuffer buff = listBuf.get(0);
System.out.println(buff.toString());
}
}
options
A)Hello
B)Compile error
C)java.lang.ClassCastException
D)null
Correct answer is : C
Explanations : java.lang.String cannot be cast to java.lang.StringBuffer at the code StringBuffer buff = listBuf.get(0);
So thows java.lang.ClassCastException.
Bom to fazendo ela aqui e tá dando erro de compilação, a resposta está errada? ou eu que estou hehe?
- questões da prova não seriam tão desleixadas assim