3 回答

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個贊
你確定你需要上課嗎?
可能是一個簡單的字段聲明就足夠了:
public class ABC extends CDE implements EFG {
public String testValue;
public String anotherValue;
public void firstMethod(String valueOne, String valueTwo) {
// do whatever you wish with testValue and anotherValue
}
public void readMethod() {
// here you have access to both variables
}
}

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個贊
也許這符合您的標(biāo)準(zhǔn)?由于內(nèi)部類的范圍,您當(dāng)前要求的內(nèi)容是不可能的。
您還可以在構(gòu)造函數(shù)中初始化此私有類實(shí)例。
public class Sample {
class TestClass {
public String testValue;
public String anotherValue;
}
private TestClass localTest = new TestClass();
public void firstMethod(valueOne, valueTwo) {
localTest.testValue = valueOne;
localTest.anotherValue = valueTwo;
}
public void readMethod() {
localTest.testValue = "test1";
localTest.anotherValue = "anotherValue";
System.out.println(localTest.testValue);
}
}

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超8個贊
您正在聲明一個帶有方法的類,這是不對的
您需要了解類和方法的真正含義(Google Java OOP):
1-你應(yīng)該創(chuàng)建一個類并聲明你想要的變量
2-為默認(rèn)值創(chuàng)建構(gòu)造函數(shù)
3-讓設(shè)置器設(shè)置(分配)這些值
4- 制造吸氣劑來讀取這些值
添加回答
舉報