More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. Cloneable is a declaration that the class implementing it allows cloning or bitwise copy of it's object state. It is not having any method because it is a MARKER interface.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Copy Constructor is used for creating a duplicate of another object. Duplicate object will have the same state of the copied object but will have independent values in different memory locations. Copy Constructor can be useful to create duplicates of immutable objects as the Original cannot be tampered. Moreover It can be useful if base copies are required for individual requests in threading.
Help us improve. Please let us know the company, where you were asked this question :
Ans. It make sense only if we intend to modify either of the object and would like to preserve original state in other. Otherwise we can reuse the original object by making it singleton.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Here is the list of classes that implements Collections Interface - http://www.buggybread.com/2015/02/java-collections-classes-that-implement.html
Having Collection interface to extend Cloneable interface would mean necessarily implement clone method by all implementing classes. As not all collection classes allow duplicate elements, it makes no sense to clone elements for them.
Help us improve. Please let us know the company, where you were asked this question :
Ans. The prototype pattern is a creational design pattern. It is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. Prototype is used when we need duplicate copies of objects.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Its is the process of creating exact copy of an object being cloned. In Object class one native method called clone() is there which is meant for Shallow Cloning of Object. Shallow cloning means bitwise copy of an object.In case of primitive data type it will create an exact copy of primitive values as well as variables but if the object contains any reference of an object then it will not copy the referenced object rather it will create the copy of reference variable and assigned it to the old object.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Because Singleton implementation doesn't restrict it from cloning and hence we can have multiple objects when we actually don't intend it to have multiple objects.
Help us improve. Please let us know the company, where you were asked this question :