DEV Community

lou
lou

Posted on

L'interface Cloneable en Java bDarija

L'interface Cloneable howa wahd l'interface khawi kaytsema marker interface.

Kayna wahd la methode smytha clone() mojoda fla classe Object.
O had la methode clone() bach tkhdem lina flcode dialna, l mefrod elina ndiro implementation dial l'interface Cloneable. O hadchi bach flekher nqedro ndiro istinsakh lchi objet.

L'interface kay3ti hadik la classe li ghat-implementer Cloneable imkaniat istinsakh ses objets.

syntaxe

public interface Cloneable

Enter fullscreen mode Exit fullscreen mode

La classe li kat-implementer l'interface Cloneable mfrod toverride la methode clone() ziada ela anaha dir gestion dial l'exception CloneNotSupportedException

public class Etudiant implements Cloneable {   
   private String nom;
   private String prenom;
   @Override   
   public Etudiant clone() throws CloneNotSupportedException {

         return (Etudiant) super.clone();

   }
}
Enter fullscreen mode Exit fullscreen mode

bach hna flekher nste3mlo dik la methode b had tariqa:

public static void main(String[] args) {

Etudiant etd1= new Etudiant("loubna","talha");
Etudiant etd2=(Etudiant) etd1.clone();
}

Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

Didn't understand a string of your post, as this is an international community I suggest you to practise your English a bit on it, it will be fine to get used to it for your future job as well 😊

By the way if you add the name of the programming language just before the opening markdown tags it will colorize it, just like that

Syntax



```java

 // your code here

```


*Live example: *

public class Etudiant implements Cloneable {   
   private String nom;
   private String prenom;
   @Override   
   public Etudiant clone() throws CloneNotSupportedException {

         return (Etudiant) super.clone();

   }
}
Enter fullscreen mode Exit fullscreen mode

Cheers!

Collapse
 
leriaetnasta profile image
lou

Thanks for the tip

Some comments may only be visible to logged-in visitors. Sign in to view all comments.