— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet67/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   63   64   65   66   67   68   69   70   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

Exercise Solutions
Exercise
Be the Compiler:
exercise 
solutions


you are here
4
classes 
and 
objects
47
public class EchoTestDrive {
public static void main(String [] args) {
Echo e1 = new Echo();
Echo e2 = new Echo( ); // the correct answer
- or -
Echo e2 = e1; // is the bonus answer!
int x = 0;
while ( 
x < 4
) {
e1.hello();
e1.count = e1.count + 1;
if ( 
x == 3
) {
e2.count = e2.count + 1;
}
if ( 
x > 0
) {
e2.count = e2.count + e1.count;
}
x = x + 1;
}
System.out.println(e2.count);
}
}
class 
Echo
{
int 
count
= 0;
void 
hello( )
{
System.out.println(“helloooo... “);
}
}
File Edit Window Help Assimilate
%java EchoTestDrive
helloooo...
helloooo...
helloooo...
helloooo...
10
I am compiled from a .java file.
My instance variable values can be 
different from my buddy’s values.
I behave like a template.
I like to do stuff.
I can have many methods.
I represent ‘state’.
I have behaviors.
I am located in objects.
I live on the heap.
I am used to create object 
instances.
My state can change.
I declare methods.
I can change at runtime.
class
object
class
object, method
class, object
instance variable
object, class
method, instance variable
object
class
object, instance variable
class
object, instance variable
Pool Puzzle
Who am I?
Note: both classes and objects are said to have state and behavior. 
They’re defined in the class, but the object is also said to ‘have’ 
them. Right now, we don’t care where they 
technically live.

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   63   64   65   66   67   68   69   70   ...   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