1. What access control levels do classes have and what does class access mean?
Default or public. A can instantiate, extend, access members of B
2. What implicit access modifiers do interfaces have?
Implicit abstract class, implicit public static final instance vars, implicit public abstract methods
3. How many class declaration per file?
1 public, >1 default
4. 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
5. Can subclass see parent's private members?
No, private members not inherited. Defining same method name is not overriding.
6. 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
7. What modifiers can be applied to local vars inside methods?
Never access modifiers. Only "final"
8. 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
9. Can abstract classes be instantiate?
10. Do I need to import from same package?
11. Abstract final
12. How can synchronized by used?
Only on methods or code blocks, can combine with any access modifiers or final
13. What is native modifier and how is it used?
Only on methods, implemented in platform depended code, semicolon to omit
14. What is strictfp modifier and how is it used?
Only on classes and methods
15. What are the rules for var args?
Last in parameters
Only one per method
16. What are the rules for constructors?
No return type
Any access modifier
Can't be static, final, abstract
17. What are numerical primitives' ranges in bits?
Byte 8, short 16, int 32, long 64, float 32, double 64
18. What is char primitive type?
16 bit Unicode. Can assign to number type bigger than short.
19. What modifiers can be used on instance variables?
3 access, final, transient, volatile
NOT abstract, synchronized, strictfp, native, static
20. Do local or instance variables have default values upon declaration but before instantiation?
Instance have default
21. What is shadowing and what use case does it have?
Local var name same as instance var name.
Commonly used by method parameters
22. 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.
23. What does final modifier mean for class, method, variable?
Can't be subclassed
Can't be overridden
Can't have new value/reference
24. Explain transient, volatile
Private copy for each thread
Both modifiers can only be used on instance vars
25. 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
26. What are constant specific class body?
Specific constant overrides enum method.
27. 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.
28. 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.