1. Declarations and Access Control Flashcards
How identifiers can begin, what chars can have after that and what could be their length ?
Identifiers can begin with a letter, an underscore, or a currency character. After the first character, identifiers can also include digits. Identifiers can be of any length.
How you can compile and execute Java programs without IDE ?
You can compile and execute Java programs using the command-line programs javac and java, respectively.
What is the special signature of main() method? Could it be overloaded ? Write three different legal declarations of main() method.
The only versions of main() methods with special powers are those versions with method signatures equivalent to public static void main(String[] args). main() can be overloaded.
static public void main(String[] args)
public static void main(String… x)
static public void main(String bang_a_gong[])
Static imports syntax ?
the syntax is import static…
How many public and nonpublic classes can have a source code file ?
A source code file can have only one public class and more than one nonpublic class.
How many packages and imports can have a source file ?
A file can have only one package statement, but it can have multiple imports.
Order of import, class declaration and package ?
The package statement (if any) must be the first (noncomment) line in a source 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.
How many access modifiers, general/class access levels you know?
There are three access modifiers: public, protected, and private. There are four access levels: public, protected, default, and private. Classes can have only public or default access.
What is the difference between default and public class 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.
What nonaccess modifiers can have a class ?
Classes can also be modified with final, abstract, or strictfp.
is the following class definition correct and why:
public final abstract class Tortoise { }
A class cannot be both final and abstract. By definition, an abstract class is one that must be extended by another class to be instantiated, whereas a final class can’t be extended by another class. By marking an abstract class as final, you’re saying the class can never be instantiated, so the compiler refuses to process the code.
Can an abstract class be instantiated ?
When a class is required to be marked as an abstract one?
What types of method can have an abstract class ?
When the abstract methods in an abstract class should be implemented ?
An abstract class cannot be instantiated.
A single abstract method in a class means the whole class must be abstract.
An abstract class can have both abstract and nonabstract methods.
The first concrete class to extend an abstract class must implement all of its abstract methods.
What are the differences and similarities between interfaces and abstract classes ? Can an abstract class implement an interface ?
An interface is like a 100% abstract class and is implicitly abstract whether you type the abstract modifier in the declaration or not.
An interface can have only abstract methods, no concrete methods allowed.
Interface methods are by default public and abstract—explicit declaration of these modifiers is optional.
A class implementing an interface can itself be abstract. An abstract implementing class does not have to implement the interface methods (but the first concrete subclass must).
What is called class member ?
Methods and instance (nonlocal) variables are known as “members.”
What access modifiers can class members have ?
Members can use all four access levels: public, protected, default, and private.