Share knowledge�.

3/December/2007

method parameter

Filed under: Java - Administrator @ 4:30 pm

class Satu{

    Satu(){
    }

    public static void main(String aaa[]){
      Satu panggil = new Satu();

      panggil.hitung(12,56);
        
    }

    void cetak(int a,int b){
        int c = a + b;
        System.out.println("Hasil penjumlahan ="+c);
    }
}

+ method cetak(int a,int b) mengartikan ia harus dipanggil dengan memasukan dua buah data ber tipe int.
+ contoh pemanggilan:
. . .
      Satu panggil = new Satu();
      panggil.hitung(12,56);
      panggil.hitung(16,36);
. . .
artinya, menggunakan method hitung untuk menjumlahkan  12 dengan 56, kemudian digunakan menjumlahkan 16 dengan 36 yang hasil
perhitungan ditampilkan pada layar.
+ di perbolehkan membuat method engan nama yang sama asalakan berparameter beda, contoh:
. . .
    void cetak(int a,int b){
            bla bla bla …..
    }
    void cetak(int a,int b,int c){
            bla bla bla ….
    }
. . .
Hal ini diistilahkan dengan overloading.

Comments »

The URI to TrackBack this entry is: http://computerteach.blogsome.com/2007/12/03/method-parameter/trackback/

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Alex King