1.private, protected,static cannot be used to decorate interface.
2.java is performed in the same way as a value pass when processing a base data type (for example, int, char,double), except that other types are performed by reference. The object references the pass in addition to the function call and is passed with reference when the "=" assignment is used.
3. How to copy objects in Java, not references. Example:
Class OBJ implements cloneable{private int a=0;public int Geta () {return A;} public void SetA (int b) {this.a=b;} public void Changeda () {this.a=1;} Public Object Clone () {object o=null;try{0= (OBJ) Super.clone ();} catch (Clonenotsupportedexception e) {e.printstatcktrace ();} return o;}} public class Testref{public static void Main (String args[]) {obj a= new obj (); obj b= (obj) a.clone (); B.changeda (); System.out.println ("A:" +a.geta ()); System.out.println ("B:" +b.geta ());}}
The result of the program operation is:
a:0
B:1
Therefore, to assign a class, you must implement the Cloneable interface. Steps:
(1) The implementation of clone of the tired first to inherit the Cloneable interface. The Cloneable interface is essentially an identity interface (there is no method, that is, an empty interface)
(2) override the Clone () method of the object class in the class.
(3) Call Super.clone () in the Clone () method.
(4) Point the shallow copy reference to the new clone of the prototype object.
When a class has complex object properties in addition to the base data, the Clone () method is overridden to complete a deep copy of the properties of the non-primitive type. Examples are as follows:
Class OBJ implements Cloneable{private date birthday = new Date ();p rivate int a=0;public int Geta () {return A;} public void SetA (int b) {this.a=b;} public void Changeda () {this.a=1;} Public Date GetDate () {return birthday ();} public void SetDate (date date) {this.birthday = date;} public void ChangeDate () {this.birthday.setMonth (4); } Public Object Clone () {object o=null;try{0= (OBJ) Super.clone ();} catch (Clonenotsupportedexception e) {e.printstatcktrace ();} Implements a deep copy of o.birthday= (Date) this.getdate (). Clone (); return o;}} public class Testref{public static void Main (String args[]) {obj a= new obj (); obj b= (obj) a.clone (); B.changeda (); System.out.println ("A:" +a.geta ()); System.out.println ("B:" +b.geta ());}}
The difference between shallow copy and deep copy:
Shallow copy: All variables of the copied object contain the same value as the original object, and all other object references still point to the same value as the original object, and all references to other objects still point to the original object.
Deep copy: All variables of the copied object contain the same values as the original object, and go out of those variables that refer to other objects. Those referencing other object variables will point to the new object being copied, and no longer the original referenced objects are copied again.
Java Learning notes----You may not know that knowledge, object copying and referencing