그래서 클래스가 테스트 불렀다 : 당신이 볼 수 있듯이자바, 클래스의 모든 변수 값을 얻을
public class Test{
protected String name = "boy";
protected String mainAttack = "one";
protected String secAttack = "two";
protected String mainType"three";
protected String typeSpeak = "no spoken word in super class";
//Somehow put all the class variables in an Array of some sort
String[] allStrings = ??(all class' strings);
//(and if you feel challenged, put in ArrayList without type declared.
//So I could put in, not only Strings, but also ints etc.)
public void Tester(){
//Somehow loop through array(list) and print values (for-loop?)
}
}
, 나는 배열이나 ArrayList를 (또는 비슷한) 모든 클래스 변수를 넣을 자동으로 그리고 나서 배열을 반복하고 값을 인쇄/가져올 수 있기를 원합니다. 향상된 루프를 사용하는 것이 바람직합니다.
getters와 setters를 사용하십시오. –
왜 배열을 사용하여 시작하지 않으시겠습니까? 왜 별도의 변수가 필요한가요? –
이것은 끔찍한 생각입니다. 이런 식으로 수업을 설계하지 마십시오. 성찰을 시험하기 위해서라면 괜찮아. '반사 '가 핵심 단어입니다. –