— Scott McNealy, Sun Microsystems Chairman, President and ceo


In your tester, make an object and access



Download 40,57 Mb.
Pdf ko'rish
bet57/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   53   54   55   56   57   58   59   60   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

3
In your tester, make an object and access 
the object’s variables and methods
instance variables
a method
just a main method
(we’re gonna put code 
in it in the next step)
make a Dog object
use the dot operator (.) 
to set the size of the Dog
and to call its bark() method
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;
The Dot Operator (.)
If you already have some OO savvy, 
you’ll know we’re not using encapsulation. 
We’ll get there in chapter 4.


you are here
4
classes 
and 
objects
37
Sharpen your pencil
object 1
object 2
object 3
title
genre
rating
title
genre
rating
title
genre
rating
MOVIE
title
genre
rating
playIt()
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”;

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   53   54   55   56   57   58   59   60   ...   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