Chapter 1: Java Building Blocks Flashcards
T or F: A file can contain multiple classes.
True. But at most one public class.
T or F: A public class within the file ClassA.java can be named ClassB
False. A public class must be in a file of the same name
What is the file extension is used for bytecode files?
.class
T or F: Every java file requires a package declaration
False. Package declaration is optional
T or F: Constructors can have a return type
False
T or F: It is optional to include a constructor in a class
True. There is a default do-nothing constructor
Where do you put code initializer blocks?
Within a class, outside of methods.
Which runs first, code initializer block or field initialization?
Depends on the order they appear in the class
When does a constructor’s code block run?
After field and initializer blocks are done
T or F: You can refer to a field before it is initialized
False
What type of data does the following primitive hold?
Boolean
True or false
What type of data does the following primitive hold?
byte
8-bit integral value
What type of data does the following primitive hold?
short
16-bit integral value
What type of data does the following primitive hold?
int
32-bit integral value
What type of data does the following primitive hold?
long
64-bit integral value
What type of data does the following primitive hold?
float
32-bit floating-point value
What type of data does the following primitive hold?
double
64-bit floating-point value
What type of data does the following primitive hold?
char
16-bit Unicode value
T or F: A float literal doesn’t need the ‘f’ after it
False. Floating point literals are assumed to be doubles unless the ‘f’ is present
What is the max value of a byte?
127
What is the min value of a byte?
-128
What does it mean to have a numeric literal followed by an ‘L’?
It’s data type is long
How do you write an octal literal?
Prefix with ‘0’
How do you write a hex literal?
Prefix with ‘0x’