Anda di halaman 1dari 3

Contoh Program dalam Java /* @author shallmee */ public class Televisi { private int vol = 0; private boolean on = false;

private String chanl; private String retn; //constructor public Televisi (String channel, boolean inputan, int volume) { vol = volume; on = inputan; chanl = channel; // untuk menampilkan System.out.println ("\n Object Channel Televisi" +channel+ "Sukses dibuat"); } //fungsi public void hidupkan_televisi () { if (on == true) retn = "Televisi Telah Dihidupkan"; else retn = "Televisi Mati"; if (vol > 0) retn += "Dengan Volume" +vol; System.out.println(retn); } public static void main(String[] args) { // TODO code application logic here Televisi ind = new Televisi ("Indosiar", true, 20); ind.hidupkan_televisi(); Televisi sctv = new Televisi ("SCTV", true, 10); sctv.hidupkan_televisi(); Televisi rcti = new Televisi ("RCTI", false, 0); rcti.hidupkan_televisi(); } }

OOP2_Class,Method,Modifier_ShallMee

Contoh Program dalam C#


/* Created by shallmee */ using System; namespace televisi { public class Televisi { private int vol =0; private Boolean on = false; private String chanl; private String retn; public Televisi(String channel, Boolean inputan, int volume) { vol = volume; on = inputan; chanl = channel; Console.WriteLine ("Object Channel Televisi"+channel+"Telah Dibuat"); } public void hidupkan() { if (on==true) { retn = "Televisi Telah Dihidupkan"; } else retn = "Televisi Mati"; if (vol>0) { retn+="Dengan Volume"+vol; } Console.WriteLine(retn); } } class Program { public static void Main(string[] args) { Televisi ind = new Televisi("indosiar", true, 10); ind.hidupkan(); Console.WriteLine(); Console.WriteLine(); Televisi sctv = new Televisi("sctv", true, 10); sctv.hidupkan(); Console.WriteLine(); Console.WriteLine(); Televisi rcti = new Televisi("rcti", true, 10); rcti.hidupkan(); Console.WriteLine(); Console.WriteLine(); Console.Write("Press any key to continue . . . "); Console.ReadKey(true); } } }

OOP2_Class,Method,Modifier_ShallMee

Contoh Class Method dan Modifier C++


using namespace std; class jumlah { public : int tambah (int x, int y) { int z; z=x+y; return z; } void hasilJumlah(int data) { count << Hasil Jumlah = <<<div=> } }; int nilai() { Int i = 0; count << Inputkan Nilai = ; cin >> i; return i; } int main(int argc, char*argv[]) { Jumlah prossess; int x,y,z; x=nilai(); y=nilai(); z=prossess.tambah; prossess.hasil(z); system(PAUSE); return EXIT_SUCCESS; } <<>

OOP2_Class,Method,Modifier_ShallMee

Anda mungkin juga menyukai