生活随笔
收集整理的這篇文章主要介紹了
JAVA的封装步骤
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.封裝實(shí)現(xiàn)的步驟
封裝就是隱藏屬性,通過(guò)我們的方法來(lái)得到屬性
具體樣例:
package com
.imooc
;public class Inital {public static void main(String
[] args
) {hello phone
= new hello();hello phone2
=new hello(5.0f,1.4f,2.0f);phone2
.cpu
=35;phone2
.setScreen(6.8f);System
.out
.println("screen:"+phone2
.getScreen());System
.out
.println(phone2
.cpu
);}}
package com
.imooc
;
import java
.util
.Scanner
;
import java
.util
.Arrays
;
public class hello {private float screen
;float cpu
;private float mem
;private int var
=14;public float getScreen() {return screen
;}public void setScreen(float newScreen
) {screen
= newScreen
;}public hello() {System
.out
.println("輸出流");}public hello(float newScreen
,float newCpu
,float newMem
) {screen
=newScreen
;cpu
=newCpu
;newMem
=mem
;System
.out
.println(screen
);}
總結(jié)
以上是生活随笔為你收集整理的JAVA的封装步骤的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。