Flashcards in 1.Declarations and Access Control Deck (81)
Identifiers can begin with...
a letter, an underscore, or a currency character
After the first character...
identifiers can also include digits
Identifier length can be...
Identifiers can be of any length
You can compile and execute Java programs using the command-line programs...
java and javac. Both programs support a variety of
The only versions of main() methods with special powers are those
versions with method signatures equivalent to...
public static void main(String args)
can main be overloaded?
what does an import statement is good for?
only job is to save keystrokes
why do we use asterisk (*) in imports?
to search through the contents of a single
what is the syntax for static imports?
how many public classes can a source file have?
If the source file contains a public class, what can be the class names?
the filename must match the
public class name
How many package statements can a file have?
Where is the correct place for package statement
the first line in a source file
Where is the correct place for import statement
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.
how the package and import statements apply to classes in a file
to all classes in the file
how many nonpublic classes can a file have?
more than one
How can we name nonpublic classes?
no public classes have no naming restrictions
What are class access modifiers?
public, protected, and private
How many access levels are there?
public, protected, default, and private
Which accesses a class can have?
public or default access
A class with default access can be seen..
only by classes within the same
A class with public access can be seen by...
all classes from all packages.
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
Nonaccess modifiers for classes are...
final, abstract, or strictfp
Can a class be both final and abstract?
What does it mean for a class to have "final" as modifier?
A final class cannot be subclassed.
What does it mean for a class to have "abstract" as modifier?
An abstract class cannot be instantiated
Can a non abstract class have an abstract method inside?
No. A single abstract method in a class means the whole class must be abstract.
Can an abstract class have non abstract methods?
Yes, an abstract class can have both abstract and nonabstract methods.