Что выведет следующий код?

public class Test {
    public static void main(String[] args) throws Exception {
        Test test = new Test();
        Test testCloned = (Test) test.clone();
        Test test2 = test;
        boolean res = test.toString().equals(test2.toString());
        boolean resClone = testCloned.toString().equals(test.toString());
        System.out.println(res);
        System.out.println(resClone);
    }
}
Explanation
Произойдёт java.lang.CloneNotSupportedException, т.к. класс Test должен был реализовывать интерфейс Cloneable.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes