public class Test {
String [] arrayA = new String [5]; // Your Array
arrayA[0] = "Testing";
public Test(){ // Your Constructor
method1(arrayA[0]); // Calling the Method
}
public void method1 (String yourString) { // Your Method
System.out.println(yourString);
}
}
new Test();
メイン クラスでは、Test のインスタンスを作成してメイン クラスからメソッドを呼び出したい場合は、OR を呼び出すことができます。
public class Test {
public Test(){ // Your Constructor
// method1(arrayA[0]); // Calling the Method // Commenting the method
}
public void method1 (String yourString) { // Your Method
System.out.println(yourString);
}
}
メイン クラスで、クラスに test のインスタンスを作成しますmain
。
Test test = new Test();
String [] arrayA = new String [5]; // Your Array
arrayA[0] = "Testing";
test.method1(arrayA[0]); // Calling the method
そして、メソッドを呼び出します。
編集:
method
ヒント: andvariable
を大文字で始めないというコーディング標準があります。
また、クラスの宣言には()
.