What access control levels do classes have and what does class access mean?
Default or public. A can instantiate, extend, access members of B
What implicit access modifiers do interfaces have?
Implicit abstract class, implicit public static final instance vars, implicit public abstract methods
How many class declaration per file?
1 public, >1 default
What access controls levels do members have and what does member access mean?
Public, protected, default, private. A's method can access B's members, subclass can inherit parent member
Can subclass see parent's private members?
No, private members not inherited. Defining same method name is not overriding.
Default vs protected members
Protected: same package can access by ref (ref.member) or by inheritance (this.parentMember), diff package access by inheritance not ref, same package cannot access by ref an already inherited.
Default: same package can access by inherit or ref
What modifiers can be applied to local vars inside methods?
Never access modifiers. Only "final"
What rule relates abstract classes to their methods and implementations?
Abstract class can have 0 or more abstract methods
1 or more abstract methods always require class to me abstract
First concrete class must implement all outstanding abstract methods
Can abstract classes be instantiate?
Do I need to import from same package?
How can synchronized by used?
Only on methods or code blocks, can combine with any access modifiers or final
What is native modifier and how is it used?
Only on methods, implemented in platform depended code, semicolon to omit
What is strictfp modifier and how is it used?
Only on classes and methods
What are the rules for var args?
Last in parameters
Only one per method
What are the rules for constructors?
No return type
Any access modifier
Can't be static, final, abstract
What are numerical primitives' ranges in bits?
Byte 8, short 16, int 32, long 64, float 32, double 64
What is char primitive type?
16 bit Unicode. Can assign to number type bigger than short.
What modifiers can be used on instance variables?
3 access, final, transient, volatile
NOT abstract, synchronized, strictfp, native, static
Do local or instance variables have default values upon declaration but before instantiation?
Instance have default
What is shadowing and what use case does it have?
Local var name same as instance var name.
Commonly used by method parameters
Explain arrays in java
Array is always object on heap. Can only hold same or subclasses of same types. Can't expand/contract dynamically (use java collections). Declare, construct, initialize. JVM doesn't allocate space until initialization.
What does final modifier mean for class, method, variable?
Can't be subclassed
Can't be overridden
Can't have new value/reference
Explain transient, volatile
Private copy for each thread
Both modifiers can only be used on instance vars
Explain enum declaration rules
Declared at file level can only have default or public access
Declare inside class. Semicolon optional if no more enum declaration code follows.
Cannot declare inside methods
What are constant specific class body?
Specific constant overrides enum method.
What are java rules for extending and implementing interfaces?
Interface can extend multiple interfaces. Concrete class that implements interface must implement all in inheritance tree. Abstract class doesn't have to. Interface can extend multiple interfaces.
Do static methods have direct access to non static vars or methods?
No, need to initialize a reference to the object first. Otherwise compile error. Static methods don't know about the current instance.