|
1. Which of the following are true statements?
(Choose all that apply.) A. Java allows operator overloading.
2. Which of the following are true?
A. javac compiles a .class file into a .java file.
3. Which of the following are true if this command
completes successfully assuming the CLASSPATH is not set?
java MyProgram.java A. A .class file is created.
The program needs to be run as java MyProgram.
4. Given the following classes, which of the following
can independently replace INSERT IMPORTS HERE to make the code compile?
package aquarium;
A. import aquarium.*;
5. Which are included in the JDK?
A. javac
6. Given the following classes, what is the maximum number of imports that can be removed and have the code still compile? package aquarium;
package aquarium;
import
import
import aquarium.*; public class Tank {
A. 0
7. Given the following classes, which of the following
snippets can independently be inserted in place of INSERT IMPORTS HERE
and have the code compile?
package aquarium;
package
package employee;
A. import aquarium.*;
8. Given the following command, which of the following
classes would be included for compilation?
javac *.java A. Hyena.java
9. Given the following class, which of the following
calls print out Blue Jay?
public class
A. java BirdDisplay Sparrow Blue Jay
10. Which of the following are legal entry point methods
that can be run from the command line?
A. private static void main(String[] args)
--- Answers: 1. B, E. C++ has operator overloading and pointers. Java made a
point of not having either. Java does have references to objects, but these
are pointing to an object that can move
B is correct because Java is platform independent. Option E is correct because Java is object-oriented. While it does support some parts of functional programming, these occur within a class. 2. C, D. Java puts source code in .java files and bytecode in .class
files. It does not use a .bytecode file. When running a Java program, you
pass just the name of
3. C, D. This example is using the single-file source-code launcher. It compiles in memory rather than creating a .class file, making option A incorrect. To use this launcher, programs can only reference classes built into the JDK. Therefore, option B is incorrect, and options C and D are correct. 4. C, D. The Tank class is there to throw you off since it isn’t used by AquariumVisitor. Option C is correct because it imports Jelly by class name. Option D is correct because it imports all the classes in the jellies package, which includes Jelly. Option A is incorrect because it only imports classes in the aquarium package—Tank in this case —and not those in lowerlevel packages. Option B is incorrect because you cannot use wildcards anywhere other than the end of an import statement. Option E is incorrect because you cannot import parts of a class with a regular import statement. Option F is incorrect because options C and D do make the code compile. 5. A, C, D, E. Eclipse is an integrated development environment (IDE).
It is not included in the Java Development Kit (JDK), making option B incorrect.
The JDK comes with a number of command-line tools including a compiler,
packager, and documentation, making options A, D, and E correct. The JDK
also includes the
6. E. The first two imports can be removed because java.lang is automatically imported. The following two imports can be removed because Tank and Water are in the same package, making the correct option E. If Tank and Water were in different packages, exactly one of these two imports could be removed. In that case, the answer would be option D. 7. A, B, C. Option A is correct because it imports all the classes in the aquarium package including aquarium.Water. Options B and C are correct because they import Water by class name. Since importing by class name takes precedence over wildcards, these compile. Option D is incorrect because Java doesn’t know which of the two wildcard Water classes to use. Option E is incorrect because you cannot specify the same class name in two imports. 8. A, B. The wildcard is configured for files ending in .java, making options E and F incorrect. Additionally, wildcards aren’t recursive, making options C and D incorrect. Therefore, options A and B are correct. 9. B. Option B is correct because arrays start counting from zero and strings with spaces must be in quotes. Option A is incorrect because it outputs Blue. C is incorrect because it outputs Jay. Option D is incorrect because it outputs Sparrow. Options E and F are incorrect because they output java.lang.ClassNotFoundException:
10. E. Option E is the canonical main() method signature. You need to memorize it. Option A is incorrect because the main() method must be public. Options B and F are incorrect because the main() method must have a void return type. Option C is incorrect because the main() method must be static. Option D is incorrect because the main() method must be named main. |
|
Java Books
Do you have a Java Problem?
Return to : Java Programming Hints and Tips All the site contents are Copyright © www.erpgreat.com
and the content authors. All rights reserved.
|