clone() object....

ashie

ashie

@ashie-F59bNm Oct 25, 2024
why do we need to use clone() object...
can anyone tell me sme scenario where we can use this.
an eg. can also be appreciated...

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • ashie

    ashie

    @ashie-F59bNm Jun 15, 2012

    why do we need to use clone() object...
    can anyone tell me sme scenario where we can use this.
    an eg. can also be appreciated...
  • ankur8819

    ankur8819

    @ankur8819-Y8pKwX Jun 15, 2012

    ashie
    why do we need to use clone() object...
    can anyone tell me sme scenario where we can use this.
    an eg. can also be appreciated...
    you do cloning if you need say a local copy of an Object.When you are going to modify the current object but you need to have previous state of your Object as well.
    Refer to
    <a href="https://javapapers.com/core-java/java-clone-shallow-copy-and-deep-copy/" target="_blank" rel="nofollow noopener noreferrer">Java Clone, Shallow Copy and Deep Copy - Javapapers</a>
    for more info
  • Vikash Verma

    Vikash Verma

    @vikash-verma-jF0MOy Jun 19, 2012

    You need to create clone of an object when you want to create a new object having same state as another existing object without calling the constructor,basically it prevents the calling of constructor for creation of new object...😎