오버로딩1 [자바]오버로딩 생활코딩에서 오버로딩 개념을 복기하려고 포스팅. 우리는 매개변수를 왜 써야할까? 예를들어 매개변수의 수에 따라서 메소드 명이 달라지게 되는건 효율적이지 못하다. //원래 메소드 c1.setOprands(); //매개변수가 2개일때 c1.setOprands2(10,20); //매개변수가 3개일때 c1.setOprands3(10,20,30); 그럴때는 메소드 이름은 같게하고 매개변수의 수만 다르게 해주면된다. 이것을 메소드 오버로딩이라고 한다. class Calculator{ int left, right; int third = 0; public void setOprands(int left, int right){ System.out.printLn(“setOprands(int left, int right)”);.. 2021. 10. 10. 이전 1 다음