C#中的get,set与java中的get,set有什么区别??

C#:

 public class studyingClass
    {
      private float width=2;     
      public float Width   
      {   
          get { return this.width; }
          set { width = value; }   
      }           
    }

java:

public class Studyingclass

{

private float width=2;

public float getWidth()

{return width;}

public void setWidth(float value)

{this.width=value;}

}

java中的get set方法,一定要叫那样的名字吗??我叫get2009这样的可以吗??


心有法竹
浏览 1044回答 2
2回答

互换的青春

c# 和java一样, 用get set 作为接口名的开头让能让调用者见名识意!
打开App,查看更多内容
随时随地看视频慕课网APP