java入门第二季–封装–什么是java中的封装

43次阅读

共计 546 个字符,预计需要花费 2 分钟才能阅读完成。

封装

代码 get,set
/javaDemo2/src/com/imooc/Telphone.java
package com.imooc;

import com.sun.glass.ui.Screen;

public class Telphone {
private float screen;

public float getScreen() {
return screen;
}
public void setScreen(float newScreen) {
screen = newScreen;
}
public Telphone() {
System.out.println(“ 无参的构造方法 ”);
}
}

/javaDemo2/src/com/imooc/InitailTelphone.java
package com.imooc;

import com.sun.glass.ui.Screen;

public class Telphone {
private float screen;

public float getScreen() {
return screen;
}
public void setScreen(float newScreen) {
screen = newScreen;
}
public Telphone() {
System.out.println(“ 无参的构造方法 ”);
}

}

正文完
 0