ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • 오버로딩
    JAVA 2020. 4. 22. 10:33
    package test01;
    
    class ThisA
    
    {
    
          int num;
    
          
    
          public ThisA()
    
          {
    
                
    
          }
    
          
    
          public ThisA(ThisA a)
    
          {
    
                System.out.println("객체 오버로딩");
    
                num = a.num;
    
          }
    
          
    
          public ThisA(ThisA... a)
    
          {
    
                System.out.println("객체 여러개 오버로딩");
    
                
    
                
    
                for(ThisA b : a)
    
                {
    
                      System.out.println(b.num);
    
                }
    
          }
    
          
    
          public ThisA(int a)
    
          {
    
                System.out.println("int 오버로딩");
    
                num = a;
    
          }
    
          
    
          public void setNum (int input_num)
    
          {
    
                num = input_num;
    
          }
    
          
    
          public void display()
    
          {
    
                System.out.printf("num = %d \n", num);
    
          }
    
          
    
          public ThisA copy()
    
          {
    
                ThisA a = new ThisA();
    
                //a.num = a.num;
    
                a.num = this.num;
    
                return a;
    
          }
    
          
    
          public ThisA copy(ThisA a)
    
          {
    
                ThisA b = new ThisA();
    
                
    
                b.num = a.num;
    
                System.out.println("오버로딩");
    
                return b;
    
                
    
          }
    
    }
    
    public class TestThis02 {
    
          public static void main(String[] args) {
    
                // TODO Auto-generated method stub
    
                
    
                ThisA a1 = new ThisA();
    
                ThisA a2 = new ThisA();
    
                ThisA a3 = new ThisA();
    
                
    
                a1.setNum(10);
    
                a2.setNum(20);
    
                a3.setNum(30);
    
                
    
                a1.display();
    
                a2.display();
    
                a3.display();
    
                
    
                ThisA a4 = a1.copy();
    
                a1.display();
    
                a4.display();
    
                
    
                ThisA a5 = new ThisA().copy(a3);
    
                a5.display();
    
                
    
                ThisA a6 = new ThisA(a1);
    
                a6.display();
    
                
    
                ThisA a7 = new ThisA(15);
    
                a7.display();
    
                
    
                ThisA a8 = new ThisA(a1, a2, a3);
    
                a8.display();
    
          
    
          }
    
    }
    
    

    'JAVA' 카테고리의 다른 글

    배열출력  (0) 2020.05.06
    전달인수가 정해지지 않은경우 사용법  (0) 2020.04.22
    달력 캘린더  (0) 2020.04.22
    super, this 구분  (0) 2020.04.22
    다중테이블 출력방법  (0) 2020.04.22

    댓글

Designed by Tistory.