L'interface Cloneable en Java bDarija
lou

lou @leriaetnasta

About: Hi! I made this blog because I find that explaining things is the key to retaining information ✨

Joined:
May 6, 2022

L'interface Cloneable en Java bDarija

Publish Date: May 7 '22
8 2

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

Comments 2 total

  • JoelBonetR 🥇
    JoelBonetR 🥇May 7, 2022

    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!

Add comment