Head First Java a brain-Friendly Guide Kathy Sierra and Bert Bates



Download 17,18 Mb.
Pdf ko'rish
bet27/90
Sana22.06.2022
Hajmi17,18 Mb.
#693704
1   ...   23   24   25   26   27   28   29   30   ...   90
Bog'liq
(Head Up) Kathy Sierra Bert Bates - Head First Java, 3rd Edition Early Release-O\'Reilly Media, Inc. (2021)

THE DOT OPERATOR (.)
The dot operator (.) gives you access to an object’s state and behavior
(instance variables and methods).
// make a new object
Dog d = new Dog();
// tell it to bark by using the
// dot operator on the
// variable d to call bark()
d.bark();
// set its size using the
// dot operator
d.size = 40;


If you already have some OO savvy, you’ll know we’re not using
encapsulation. We’ll get there in 
Chapter 4
.
Making and testing Movie objects


class Movie { 
String title; 
String genre; 
int rating; 
void playIt() { 
System.out.println("Playing the movie"); 


public class MovieTestDrive { 
public static void main(String[] args) { 
Movie one = new Movie(); 
one.title = "Gone with the Stock"; 
one.genre = "Tragic"; 
one.rating = -2; 


Movie two = new Movie(); 
two.title = "Lost in Cubicle Space"; 
two.genre = "Comedy"; 
two.rating = 5; 
two.playIt(); 
Movie three = new Movie(); 
three.title = "Byte Club"; 
three.genre = "Tragic but ultimately uplifting"; 
three.rating = 127; 

}
The MovieTestDrive class creates objects (instances) of the Movie class and
uses the dot operator (.) to set the instance variables to a specific value. The
MovieTest-Drive class also invokes (calls) a method on one of the objects.
Fill in the chart to the right with the values the three objects have at the end
of main().


Quick! Get out of main!
As long as you’re in main(), you’re not really in Objectville. It’s fine for a
test program to run within the main method, but in a true OO application,
you need objects talking to other objects, as opposed to a static main()
method creating and testing objects.

Download 17,18 Mb.

Do'stlaringiz bilan baham:
1   ...   23   24   25   26   27   28   29   30   ...   90




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