/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bukua;
/**
*
* @author WINDOWS
*/
public class BukuA {
String pengarang;
String judul;
int tahunTerbit;
//membuat konstruktor
public BukuA(String pengarang, String judul){
this.judul = judul;
this.pengarang = pengarang;
}//akhir konstruktor
//membuat overloading konstruktor
public BukuA (String pengarang, String judul, int tahunTerbit){
this.pengarang = pengarang;
this.judul = judul;
this.tahunTerbit = tahunTerbit;
}
public BukuA (String pengarang){
this.pengarang = pengarang;
}
public BukuA (String Judul, int tahunTerbit){
this.judul = judul;
this.tahunTerbit = tahunTerbit;
}
//membuat method
public void infoBuku(){
System.out.println("Judul Buku "+judul);
System.out.println("pengarang "+pengarang);
System.out.println("tahun terbit "+tahunTerbit);
}
}
konstruktor
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bukua;
/**
*
* @author WINDOWS
*/
public class konstruktor {
public static void main (String []args){
BukuA bukuku = new BukuA("Dedi Gunawan","Panduan Pintar Komputer");
bukuku.infoBuku();
}
}
OverLoadingKonstruktor
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bukua;
/**
*
* @author WINDOWS
*/
public class OverLoadingKonstruktor {
public static void main (String []args) {
BukuA bukuku = new BukuA("Dedi Gunawan", "Panduan Pintar Komputer");
BukuA bukumu = new BukuA("Dedi Gunawan", "Panduan Pintar Komputer", 2000);
BukuA bukukita = new BukuA("Dedi Gunawan");
BukuA bukukami = new BukuA("Panduan Pintar Komputer", 2000);
System.out.println("Buku ku");
bukuku.infoBuku();
System.out.println("Buku mu");
bukumu.infoBuku();
System.out.println("Buku kita");
bukumu.infoBuku();
System.out.println("Buku kami");
bukumu.infoBuku();
}
}
matematika
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bukua;
/**
*
* @author WINDOWS
*/
public class Matematika {
static public double kuadrat(double nilai){
return nilai*nilai;
}
static public int kuadrat(int nilai){
return nilai*nilai;
}
static public double kuadrat(String nilai){
double bilangan;
bilangan = Double.valueOf(nilai).doubleValue();
return bilangan*bilangan;
}
}
OverLoadingMethod
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bukua;
/**
*
* @author WINDOWS
*/
public class OverLoadingMethod {
public static void main (String []args){
System.out.println("Nilai Kuadrat dari tipe data double"
+Matematika.kuadrat(20));
System.out.println("Nilai Kuadrat dari tipe data integer"
+Matematika.kuadrat(20));
System.out.println("Nilai Kuadrat dari tipe data String"
+Matematika.kuadrat(20));
}
}



Tidak ada komentar:
Posting Komentar