— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet294/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   290   291   292   293   294   295   296   297   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

Instance Variable
Static Variable


310
 
chapter 10
Exercise
BE the compiler
The Java file on this page represents a 
complete program. Your job is to play 
compiler and determine whether this 
file will compile. If it won’t compile, 
how would you fix it, and 
if it does compile, what 
would be its output?
class StaticSuper{
static {
System.out.println(“super static block”);
}
StaticSuper{
System.out.println(
“super constructor”);
}
}
public class StaticTests extends StaticSuper {
static int rand;
static {
rand = (int) (Math.random() * 6);
System.out.println(“static block “ + rand);
}
StaticTests() {
System.out.println(“constructor”);
}
public static void main(String [] args) {
System.out.println(“in main”);
StaticTests st = new StaticTests();
}
}
File Edit Window Help Cling
%java StaticTests
static block 4
in main
super static block
super constructor
constructor
Possible Output
File Edit Window Help Electricity
%java StaticTests
super static block
static block 3
in main
super constructor
constructor
Possible Output
If it compiles, which of these is 
the output?
be the 
compiler


numbers 
and
statics
you are here
4
311
This chapter explored the wonderful, static, world 
of Java. Your job is to decide whether each of the 
following statements is true or false.
1. To use the Math class, the first step is to make an instance of it.
2. You can mark a constructor with the 
static
keyword.
3. Static methods don’t have access to instance variable state of the ‘this’ object.
4. It is good practice to call a static method using a reference variable.
5. Static variables could be used to count the instances of a class.
6. Constructors are called before static variables are initialized.
7. MAX_SIZE would be a good name for a static final variable.
8. A static initializer block runs before a class’s constructor runs.
9. If a class is marked final, all of its methods must be marked final.
10. A final method can only be overridden if its class is extended.
11. There is no wrapper class for boolean primitives.
12. A wrapper is used when you want to treat a primitive like an object.
13. The parseXxx methods always return a String.
14. Formatting classes (which are decoupled from I/O), are in the java.format 
package.
C

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   290   291   292   293   294   295   296   297   ...   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