可能重複:
What is the point of setters and getters in java?爲什麼我們使用一套方法
我有一個關於設置方法的問題。請儘可能提供一些細節。 我想知道爲什麼我們使用set方法和類名。
public class Mymainclass {
Private class ClassC {
Private Mysecondclass sec = null;
public void setMymainclass(Mysecondclass second){
Mymainclass.sec= second;
}
}
}
它只是設置秒變量值嗎?如果是的話爲什麼有班級名稱?
重複的:http://stackoverflow.com/questions/1461598/what-is-the-point-of-setters-and -getters-in-java * java中setters和getters的意義是什麼?* – 2010-11-12 01:06:21
我認爲這不是重複。這不僅是setter和getter問題,而且是set方法,接着是使我感到困惑的classname。 – SilentCoder 2010-11-12 01:41:37