elect the correct answerWhich of these method of Object class can clone an object?OptionsObject clone()copy()Objectcopy()clone()
Question
elect the correct answerWhich of these method of Object class can clone an object?OptionsObject clone()copy()Objectcopy()clone()
Solution
The correct answer is Object clone(). This method of the Object class can clone an object in Java.
Similar Questions
t answerWhich of these method of Object class can clone an object?
public class Person{ int age; String name; public Person(String n, int a){ age = a; name = n; } public String toString(){ return (name+ ":" + age ); } } public class Employee extends Person implements Cloneable { public Employee(String n, int a){ super(n, a); } public Employee clone()throws CloneNotSupportedException{ return (Employee)super.clone(); } } public class Test { public static void main(String[] args) { Employee[] e1 = {new Employee("Hari",30), new Employee("geeta",23)}; Employee[] e2 = e1.clone(); e2[1].name = "rani"; System.out.println(e1[1] + ", " + e2[1]); } }
When a copy constructor may be called?Option 1When an object is constructed based on another object of the same classOption 2When an object of the class is passed (to a function) by value as an argument.Option 3When compiler generates a temporary object.Option 4All of these
Assume class DEMO. Which of the following statement(s) responsible to invoke copy constructor?1. DEMO D2(D1); // Here D1 is an already created object of class DEMO2. D2 = D1; // Here D1, D2 are already created objects of class DEMOThis problem has only one correct answerOnly 1Only 2Both 1 and 2
Which constructor function is designed to copy object of same class type?A. Copy constructorB. Create constructorC. Object constructorD. Dynamic constructor
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.