These notes below are aimed to be a quick reference to any one gearing for a Java Interview. I have broken the series in parts, and this is part one of the tutorial lesson.
Local Variables
Some Pointer Notes:
Classes
- A source code file can have only one public class.
- If the source file contains a public class, the filename must match the public class name.
- There can be more than one nonpublic class in a file.
- Files with no public classes have no naming restrictions.
- Classes can also be final or abstract, but not both at the same time.
- Classes can have only public or default access.
- A class with default access can be seen only by classes within the same package.
- A class with public access can be seen by all classes from all packages
Local Variables
- Local variables can not have access modifiers, and final is the only modifier applicable for them.
Interface
- Interface methods are by default public and abstract. Explicit declaration of these modifiers is optional.
- Interfaces can have variables declared which are by implicitly constants as they are always implicitly public, static, and final.
Polymorphism
- The reference variable's type (not the object's type), determines which methods can be called.
- Object type (not the reference variable's type), determines which overridden method is used at runtime.
Some Pointer Notes:
- Abstract class cannot be instantiated.
- Final class cannot be subclassed.
- Private instance variables and methods are not visible to subclass, so they cannot be inherited.
- Final methods cannot be overridden in a subclass.
- Abstract classes have constructors that are called when a concrete subclass is instantiated.
- Interfaces do not have constructors.