1 Packagecom.liu.u6.copy1;2 /*3 * What is the difference between a basic data type and a reference data type4 */5 Public classSJLX {6 Public intAge ;7 }8 Packagecom.liu.u6.copy1;9 Public classTESTSJLX {Ten Public Static voidMain (string[] args) { OneSystem.out.println ("*********************** basic data Type *********************8"); A intNum1=3; - intNum2=5; -System.out.println ("num1 Original value =" +num1); the //assigns the value of the NUM1 to num2 -Num2=NUM1; - //Modify the value of the num2 to see if the value of NUM1 is changed -Num2=8; +SYSTEM.OUT.PRINTLN ("num2 Modified, num1=" +num1); -System.out.println ("*********************** Reference data type *********************8"); + //instantiate a pair of images ASJLX person1=NewSJLX (); atPerson1.age=23; - //The assignment to the image is to assign the member variable to the past. -SJLX person2=Person1; -System.out.println ("Front ********" +person1.age); -Person2.age = 29; -System.out.println ("After ********" +person1.age); in - } to}
Result output:
java-basic data types differ from reference data types