JAVA/OOP개념( 다형성 )
-
다형성 - polymorphismJAVA/OOP개념( 다형성 ) 2023. 6. 15. 10:01
개념 다형성의 개념은 크게 2가지로 나누어 설명할 수 있다. 클래스의 다형성 메소드의 다형성 클래스의 다형성 하나의 타입의 참조변수로 여러타입의 객체를 참조 가능 조상클래스 타입의 참조변수로 자손클래스의 인스턴스를 참조 가능하다는 것 메소드의 다형성 메소드의 다형성은 오버로딩과 오버라이딩 크게 2가지가 있다. 오버로딩은 메소드의 메소드의 이름은 같지만, 메소드의 매개변수리스트가 다른 경우 중복정의가 가능한 것을 말한다. 매개변수 리스트라는 것은, 1. 매개변수의 갯수가 다르거나, 2. 매개변수의 자료형이 다르거나, 3. 매개변수의 순서가 다를 때 를 말한다. 위의 경우, 메소드의 오버로딩이 가능하다. 오버라이딩은 메소드의 재정의를 의미하는데, 이는 상속의 개념과 함께 언급되는 내용이다. 오버라이딩은 자세..