別のクラスからメソッドを呼び出そうとしています。私が収集したメソッドから、呼び出すメソッドはインスタンスメソッドです。私はそれを集めました。つまり、オブジェクトのインスタンス変数を使用しています。このメソッドを呼び出す簡単な方法はありますか?静的コンテキストから非静的メソッドを参照することはできません
これはmainメソッド、
public void main()
{
Test.testPetOwner();
}
であり、これは私たちがアクセスしようとすると「テスト」
public void testPetOwner()
{
String petName;
String species;
String hairCondition;
String posture;
testCompetitor();
PetOwner petOwner1 = new PetOwner();
System.out.println("What is the pet's name?");
petName = Genio.getString();
petOwner1.setPetName(petName);
System.out.println("What is the species of the pet?");
species = Genio.getString();
petOwner1.setSpecies(species);
System.out.println("What is the hair condition of the pet?");
hairCondition = Genio.getString();
petOwner1.setHairCondition(hairCondition);
System.out.println("How is the pet's posture?");
posture = Genio.getString();
petOwner1.setPosture(posture);
}
ありがとうございました!あなたが答えを見ると、いつも明白に見えます! – Struan