일부 Java 프로그래밍 경쟁에서 작업을 발견했습니다. 'text'라는 단 하나의 인수와 하나의 생성자 만 사용하여 Sentence 클래스를 만들어야합니다. 다음은 샘플 테스트 코드입니다.한 생성자 - 여러 인수
Sentence s1=new Sentence("only","CAT"),
s2=new Sentence("and", 2, "mice"),
s3=new Sentence(s1,s2,"completely","alone"),
s4=new Sentence(s3, "on the ", new Integer(32), "th street");
System.out.println(s1); Only cat.
System.out.println(s2); Only cat and 2 mice.
System.out.println(s3); Only cat and 2 mice completely alone.
System.out.println(s4); Only cat and 2 mice completely alone on the 32th street.
하나의 컨스트럭터가 서로 다른 인수 세트를 제공 할 수있는 방법은 무엇입니까? 전송 된 값을 인식하는 동적 생성자와 같은 것이 있습니까?
유형이 테스트 코드 내에서만 지원되는 것 같습니다. Dunno,이 경쟁에서 경쟁하지 않았다 :) – owca