membuat main class dengan nama ContohOverloading
sripnya
public class ContohOverloading {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Matematika b = new Matematika();
double hasil = b.tambah(100.0, 100.0);
System.out.println(hasil);
}
}
buat class Matematika
public class Matematika {
int tambah(int nilai1, int nilai2){
System.out.println("tambah() 1");
int hasil = nilai1 + nilai2;
return hasil;
}
int tambah(int nilai1, int nilai2, int nilai3){
System.out.println("tambah() 2");
int hasil = nilai1 + nilai2 + nilai3;
return hasil;
}
double tambah(double nilai1, double nilai2){
System.out.println("tambah() 3");
double hasil = nilai2 + nilai2;
return hasil;
}
}
No comments:
Post a Comment