InterviewSolution
Saved Bookmarks
| 1. |
What Is The Output Of This Program? 1. Class A { 2. Int X; 3. Int Y; 4. Void Display() { 5. System.out.print(x + " " + Y); 6. } 7. } 8. Class Output { 9. Public Static Void Main(string Args[]) { 10. A Obj1 = New A(); 11. A Obj2 = New A(); 12. Obj1.x = 1; 13. Obj1.y = 2; 14. Obj2 = Obj1.clone(); 15. Obj1.display(); 16. Obj2.display(); 17. } 18. } |
|
Answer» clone() method of OBJECT class is USED to GENERATE duplicate copy of the object on which it is called. Copy of obj1 is generated and stored in obj2. $ javac Output.java clone() method of object class is used to generate duplicate copy of the object on which it is called. Copy of obj1 is generated and stored in obj2. Output: $ javac Output.java |
|