Menu
Question Index
...

What will be the output of the following program?

public class CloneTest {
    public static void main(String[] args) {
        Engineer student = new Engineer("Ramu", 446);
        Engineer copy = student.clone();
        System.out.println(copy.name + " " + copy.rollNum);
    }
}
class Engineer {
    public Engineer(String name, int i) {
        this.name = name;
        rollNum = i;
    }
    String name;
    int rollNum;
    protected Engineer clone() {
        try {
            return (Engineer) super.clone();
        } catch (Exception e) {
            return this;
        }
    };
}


Ramu 446
(EMPTY)
Compilation Error
Runtime Error

Doubts

Problems

Topic: clone() Method And cloneable Interface In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App