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 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(); } } 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(); }
Top comments (2)
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
*Live example: *
Cheers!
Some comments may only be visible to logged-in visitors. Sign in to view all comments.