관리 메뉴

nalaolla

오브젝트 예제 1 (import) 본문

JAVA/5. Object1

오브젝트 예제 1 (import)

날아올라↗↗ 2016. 6. 22. 17:07
728x90
  1. package test.com;
  2.  
  3. public class Student {
  4.     protected int num;
  5.     protected String name;
  6.     protected String email;
  7.     protected String phone;
  8.    
  9.     public Student() {
  10.         // TODO Auto-generated constructor stub
  11.         System.out.println(num);
  12.         System.out.println(name);
  13.         System.out.println(email);
  14.         System.out.println(phone);
  15.        
  16.         this.num = 99;
  17.         this.name = "daniel";
  18.         this.email = "aaa@aaa.net";
  19.         this.phone = "010-1111-2222";
  20.     }
  21. }




  1. package test.com;
  2.  
  3. import test.student.Student;
  4.  
  5. public class StudentMain {
  6.     Student abc = new Student();
  7.     public static void main(String[] args) {
  8.         // TODO Auto-generated method stub
  9.        
  10.         //import : 다른 패키지의 클래스를 사용할 수 있도록 선언하는것
  11.         //클래스의 경로는 절대경로로 설정할 수 있다.
  12. //    test.student.Student st00 = new test.student.Student();
  13.        
  14.         //접근제한자 : public > protected > default > private
  15.        
  16.         Student st01 = new Student();
  17.         test.com.Student s2 = new test.com.Student();
  18.        
  19. //    System.out.println(st01.num);
  20. //    System.out.println(st01.name);
  21. //    System.out.println(st01.email);
  22. //    System.out.println(st01.phone);
  23.        
  24.         System.out.println(s2.num);
  25.         System.out.println(s2.name);
  26.         System.out.println(s2.email);
  27.         System.out.println(s2.phone);
  28.     }
  29.  
  30. }


728x90