class Student1{ public String name; public int age; public String address; } public class ExamEx48{ public static void main(String[] args){ Student1 stu1; stu1 = new Student1(); Student1 stu2 = new Student1(); stu1.name = "홍길동"; stu1.age = 20; stu1.address = "서울시"; stu2.name = "고길동"; stu2.age = 28; stu2.address = "수원시"; //Student1@158f9d3 : 참조 주소 System.out.println(stu1); System.out.println(stu1.name); System.out.println(stu1.age); System.out.println(stu1.address); //Student1@79a2e7 System.out.println(stu2); System.out.println(stu2.name); System.out.println(stu2.age); System.out.println(stu2.address); Student1 stu3 = stu1; //참조에 의한 복사 Student1@158f9d3 System.out.println(stu3); System.out.println(stu3.name); System.out.println(stu3.age); System.out.println(stu3.address); stu3.name = "박문수"; System.out.println(stu3.name); System.out.println(stu1.name); } }
Java