Chapter 1: Declarations and Access Control Flashcards
What can identifiers begin with?
Identifiers can begin with a letter, an underscore, or a currency character.
Can identifiers include digits?
Yes, after the first character, identifiers can also include digits.
Does an identifier have a length limit?
No, identifiers can be of any length.
What two commands are used to compile and execute Java programs?
javac and java.
What main() signature has special powers?
Method signatures equivalent to public static void main(String[] args)
Can the main() be overloaded?
Yes, main() can be overloaded.
What is the purpose of an Import statement?
An import statement’s only job is to save keystrokes.
What symbol is used to search through the contents of a single package?
asterisk (*) to search through the contents of a single
package.
What syntax is correct: “Static Import” or “Import Static”
The syntax is import static….
What type of classes can be imported?
You can import API classes and/or custom classes.
How many public classes can a source file have?
A source code file can have only one public class.
When is a filename required to have the same name as a class?
If the source file contains a public class, the filename must match the public class name.
How many package statements can a file have?
A file can have only one package statement, but it can have multiple
imports.
Where should a import statement appear in a file?
The import statements (if any) must come after the package and before the class declaration.
If there is no package statement, import statements must be the first (noncomment) statements in the source file.
What classes do package and import statements affect?
package and import statements apply to all classes in the file.
True or False: A file can only have one class.
False - A file can have more than one nonpublic class.
True or False: Files with no public classes have no naming restrictions.
True - Files with no public classes have no naming restrictions.
What are the three access modifiers?
There are three access modifiers: public, protected, and private.
What are the four access levels?
There are four access levels: public, protected, default, and private.
True or False: Classes can have protected and private access.
False - Classes can have only public or default access.
What classes can access a class with default access?
A class with default access can be seen only by classes within the same package.
What does class visitability revolve around?
Class visibility revolves around whether code in one class can
- Create an instance of another class
- Extend (or subclass) another class
- Access methods and variables of another class