Java nima Java dasturlash tili


Download 1.25 Mb.
bet23/49
Sana20.01.2023
Hajmi1.25 Mb.
#1103409
1   ...   19   20   21   22   23   24   25   26   ...   49
Bog'liq
2 5420273372074344755

class Counter{
int count=0;
Counter(){
count++;
System.out.println(count);
}
public static void main(String args[]){
Counter c1=new Counter();
Counter c2=new Counter();
Counter c3=new Counter();
}
}
Ekranda:1
1
1
Natija chiqadi ko’rib turganimzdek har safar yangi obyekt olganimizda counter o’zgaruvchisiga xotiradan yangidan joy ajratyapti.
End shu o’zgaruvchini static deb e’lon qilib natijani ko’ramiz


class Counter2{
static int count=0;
Counter2(){
count++;
System.out.println(count);
}
public static void main(String args[]){
Counter2 c1=new Counter2();
Counter2 c2=new Counter2();
Counter2 c3=new Counter2();
}
}
Ekranda:1
2
3

static methodlar

Agar funnksiya static kalit so’zi bilan bo’lsa bu funksiya static funksiya deyiladi.



Javada Method Overloading 

Class ichida nomi va turlari(data type) bir xil bo’lgan ikki yokiy undan ortiq bo’lgan methodlar bo’lasa bunday methodlar overloading methodlar deyiladi.


Overloading methodlar

  1. Parametrlari bilan farq qiladi

  2. Ma’lumot turi

  3. Ma’lumot turlari ketma ketligi bilan

Bir biridan farq qiladi
Method overloading ni static polymorphism deb ham qarashimiz mumkun

Tariff:


  1. Static polymorphism compile time dagi bog’lanish yokiy erta bog’lanish(binding) sifatida ham ma’lum

  2. Static bog’alanish(binding) compile time da sodir bo’ladi. Method overloading static bog’lanishga(binding) misol bo’ladi.

Yuqorida keltirib o’tilgan tariflar barchasi method overloading ni argumetlari xar xil bo’lgan holarlar uchun mos keladi. Endi sizlar bilan har bir holatni birma bir ko’rib chiqamiz



  1. Download 1.25 Mb.

    Do'stlaringiz bilan baham:
1   ...   19   20   21   22   23   24   25   26   ...   49




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling