Chapter 1: Declaration and Access control Flashcards
What are valid starting characters for identifiers?
letters, $, _
True or False: foo and FOO are the same identifiers.
False
Name the valid getter methods for a boolean.
getBoolean, isBoolean
Name the JavaBean methods for MyListener.
addMyListener(MyListener listener)
removeMyListener(MyListener listener)
Name the access modifiers starting with the most restrictive
private -> class only default -> package only protected -> inheritance and package only public -> anywhere
What are the non-access modifiers for classes?
final, abstract, strictfp
What is wrong? class MyObject { public abstract void myMethod(); }
Both the class and the method should have a abstract modifier.
True or False: All methods in an interface are public abstract.
True
What are variables declared in a interface?
public static final
What is wrong? class foo { void doStuff() { private final int x = 7; } }
Access modifiers can’t be used in conjuction with local variables.
Final is the only non-acces modifier that can be used
Synchronized key word can be applied to:
methods & code-blocks
Which of these methods are valid var-arg methods:
1: void doStuff(int x…)
2: void doStuff(int… x, int… y)
3. void doStuff(int… x)
4. void doStuff(int… x, int y)
5. void doStuff(int y, Animal… a)
3 & 5
Name the 8 primitives
byte, short, int, long, float, double, boolean, char
Describe the integer types from small to large
byte: 8 bits (2^7) (we lose one bit for the sign (-/+))
short: 16 bits (2^15)
int: 32 bits (2^31)
long: 64 bits (2^63)
float: 32 bits
double: 64 bits
Describe the max range for a char
char: 16 bits
No signing bit
2^16 = 0-65535