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