Pages

Konsep PBO Objek dan Class Bag-4


//--------------------
//televisi.java
//--------------------
package ObjekDanClass;

public class televisi {

    String merk, hrg;
    int bos;

    public televisi(String mrk, String tv) {
        merk = mrk;
        hrg = tv;
        System.out.println("televisi " + merk + " harga " + tv);
    }

    public void hidupkanTv() {
        System.out.println("Televisi hidup");
    }

    public void getChannel(int chan) {
        this.bos = chan;
        
    }
    public int setChannel(){
    return bos;
    }

    public void matikanTv() {
        System.out.println("Televisi mati");
    }
}
//--------------------------------------------------------

//--------------------

//mainkanTv.java
//--------------------
package ObjekDanClass;

public class mainkanTv {

    public static void main(String args[]) {
        televisi tvFlat = new televisi("Sharp", "telung juta");
        tvFlat.hidupkanTv();
        tvFlat.getChannel(3);
        System.out.println("televisi diset pada channel : " + tvFlat.setChannel());
        tvFlat.matikanTv();
    }
}
//--------------------------------------------------------

//--------------------

//output
//--------------------
televisi Sharp harga telung juta
Televisi hidup
televisi diset pada channel : 3
Televisi mati
BUILD SUCCESSFUL (total time: 0 seconds)

0 comments:

Posting Komentar