- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is object cloning in Java?
Object cloning is creating a copy of an object. The clone() method of the Object class of the java.lang package creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object.
Example
import java.util.GregorianCalendar; public class ObjectDemo { public static void main(String[] args) { GregorianCalendar cal = new GregorianCalendar(); GregorianCalendar y = (GregorianCalendar) cal.clone(); System.out.println("" + cal.getTime()); System.out.println("" + y.getTime()); } }
Output
Mon Sep 17 04:51:41 EEST 2012 Mon Sep 17 04:51:41 EEST 2012
- Related Articles
- What is the use of Object Cloning in Java?
- Advantages of Object cloning in Java
- PHP Object Cloning
- Cloning in Java\n
- Explain Deep cloning an object in JavaScript with an example.
- Cloning in C#
- What is the object class in Java?
- How to prevent Cloning to break a Singleton Class Pattern in Java?
- What is object slicing in C++ or Java?
- What happens when a subclass object is assigned to a superclass object in Java?
- What is the difference between a String object and a StringBuffer object in java?
- What is the difference between object and reference in java?
- In which state was the cloning of Dolly done?
- What is the difference between a String object and a String literal in Java?
- What is math object in JavaScript?

Advertisements