Marker and Cloneable Interface

Marker interface is an empty interface having no fields. Cloneable interface making a copy of an object respectively.

Marker Interface

It is an empty interface having no fields and methods inside it. Implementation of these interfaces will give a special definition to a class. Serializable and Clonnable interface are the example of marker interface. Cloneable interface belongs to java.lang.Cloneable and and serializable interface belongs to java.io.Serializable.

Syntax:

Public interface  {
// having no fields and methods
}

Cloneable Interface:

Cloning is similar to making a copy of an object. Below is the Employee class example where it has two fields with name and age stored in emp1 object. The clone() method will help us to make a copy of emp1 to emp2 with all field values.

Example :

OUTPUT:

Note:Accessing clone() method without implementing cloneable interface will throw CloneNotSupportedException exception

Imran Khan

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan