나는 친구들과 게임을하고있다. 메서드의 반환 값을 같은 클래스의 다른 메서드로 호출하려고합니다. 나는 정상적인 상황에서 이것을하는 법을 알고 있지만, 내가 사용하고있는 수업은 추상적이다. 나는 인터넷을 통해 해답을 찾았지만 아무 것도 발견하지 못했다. 이것은 내가 사용하고있는 약간의 코드입니다 :추상 클래스 내에서 메소드를 호출하는 방법
public abstract class Game implements ActionListener
{
public static char KBoard(char w, char a, char s, char d) //This method takes in a keyboard command from the user, and returns that char.
{
Scanner scan = new Scanner(System.in);
System.out.print("");
char kBoard = scan.next().charAt(0);
return kBoard;
}
public static int MoveX (int velocity)
{
velocity = 5;//character moves this distance when a control key is pressed
Game kBoard = new Game();//These lines here will
kboard.KBoard();//call the KBoard method from above and the char it returns^^
Switch();
{
Case w:
characterPosX -= velocity;//if the w key is pressed, character moves up
break;
Case s:
characterPosX += velocity;//if the s key is pressed, character moves down
break;
}
return characterPosX;//returns the new X position for the game character
}
}
가능한 복제 (https://stackoverflow.com/questions/27279341/calling-non-abstract-method-in-abstract-class을 -java) – Debabrata
코드를 게시 할 때 의사 코드가 아닌 실제 코드를 게시하십시오. 게시 한 코드에는 컴파일 할 필요가없는 다양한 실수가 있습니다. 실제 문제와 관련이없는 사소한 실수입니다. 또한 코드를 게시했지만 사용자가 원하는 것과 비교되는 내용에 대해서는 언급하지 않았습니다. 또한 Java 명명 규칙을 따르기를 강력히 권장합니다. –