Java - Interview Questions and Answers on Clone

Q1.  What are the methods of Object Class ?

Ans. clone() - Creates and returns a copy of this object.
equals() - Indicates whether some other object is "equal to" this one.
finalize()  - Called by the garbage collector on an object when garbage collection determines that there are no more references to the object
getClass() - Returns the runtime class of an object.
hashCode() - Returns a hash code value for the object.
toString() - Returns a string representation of the object.
notify(), notifyAll(), and wait() - Play a part in synchronizing the activities of independently running threads in a program.

Q2.  What are Marker Interfaces ? Name few Java marker interfaces ?

Ans. These are the interfaces which have no declared methods.

Serializable and cloneable are marker interfaces.

Q3.  What is a cloneable interface and what all methods does it contain?

Ans. It is not having any method because it is a MARKER interface.

Q4.  What are different ways of object creation in Java ?

Ans. Using new operator - new xyzClass()
Using factory methods - xyzFactory.getInstance( )
Using newInstance( ) method - (Class.forName(“xyzClass”))emp.newInstance( )
By cloning an already available object - (xyzClass)obj1.clone( )