What will the following code print out to console?

public class Exam  {
    public static void main(String[] arg) {
        Object obj = null;
        String str = new String("str");
        str = (String) obj;
        obj = new String("obj");
        System.out.print(obj + ", " + str);  
    }
}
Explanation
The next commands will be executed in order:
1. obj is initialized with null
2. str is initialized with new String object with value "str"
3. null is assigned to str
4. "obj" string is assigned to obj

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты