— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet262/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   258   259   260   261   262   263   264   265   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

%javac TestMath
TestMath.java:3: Math() has private 
access in java.lang.Math
Math mathObject = new Math();
^
1 error
Math mathObject = new Math();
If you try to make an instance of 
class Math:
You’ll get this error:
int x = Math.round(42.2);
int y = Math.min(56,12);
int z = Math.abs(-343);
These methods never use 
instance variables, so their 
behavior doesn’t need to 
know about a specific object.


numbers 
and
statics
you are here
4
275
The difference bet ween regular 
(non-static) and static methods
Java is object-oriented, but once in a while you have a special case, 
typically a utility method (like the Math methods), where there is 
no need to have an instance of the class. The keyword 
static 
lets 
a method run without any instance of the class. A static method means 
“behavior not dependent on an instance variable, so no instance/object 
is required. Just the class.”
Politik
Coldplay
Song
s2
s2.play();
s3.play();
Calling play() on this 
reference will cause 
“Politik” to play. 
Calling play() on this 
reference will cause 
My Way” to play. 
My Way
Sex Pistols
Song
s3
Song o
bj
ec

public class Song {
String title;
public Song(String t) {
title = t;
}
public void play() {
SoundPlayer player = new SoundPlayer();
player.playSound(title);
}
public static int min(int a, int b){

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   258   259   260   261   262   263   264   265   ...   555




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

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish