1. Which of the following is not a reason to create a package? (a)To group relat
ID: 3768904 • Letter: 1
Question
1. Which of the following is not a reason to create a package? (a)To group related classes (b)To make it easy to reuse classes (c)To prevent other developers from using the class (d)To make finding classes easier
2. To include a class in a package, you (a)code an import statement as the first statement of the class (b)code a package statement as the first statement in the class file (c)code the name of the package in the class declaration
3. What must you do to use a class that you’ve stored in a package from another application? (a)Nothing; it’s automatically available to other applications. (b)Code an import statement for the class. (c)Copy the directories and files of the package to the root directory of the application. (d)Both b and c.
4. Which of the following is a benefit of using javadoc comments? (a)They make your classes easier to debug. (b)They allow other programmers to view the source code for your class. (c)They make it easy for other programmers to learn about your class. (d)They show other programmers how to code a class.
5. Which of the following is a valid javadoc comment? (a)// Calculates the balance due // (b)/* Calculates the balance due */ (c)/* Calculates the balance due **/ (d)/** Calculates the balance due */
6. You can use the javadoc tool to generate the documentation for (a)a single class (b)a single package (c)all related packages (d)all of the above (e)b and c only
7. Which of the following is not true about the documentation you generate using the javadoc tool? (a)It indicates the package that a class belongs to. (b)It lists all public methods of the class. (c)It includes the code that implements each documented method. (d)It lets you view classes by package.
8. Which of the following is an advantage of coding two or more classes in the same file? (a)You have fewer java files to manage. (b)You have fewer class files to manage. (c)It’s easier to find the source code for a class. (d)It makes it easier to reuse a class.
9. Which of the following is not true about an inner class? (a)It can contain static variables and methods. (b)It can contain instance variables and methods. (c)It can access instance variables and methods of the outer class. (d)It can access static variables and methods of the outer class.
10. Which of the following is not true about a static inner class? (a)It can contain static variables and methods. (b)It can contain instance variables and methods. (c)It can access instance variables and methods of the outer class. (d)It can access static variables and methods of the outer class.
11. Each constant within an enumeration is assigned (a)an integer value beginning with zero (b)an integer value beginning with one (c)the integer value you specify
12. Which of the following can you not do with an enumeration? (a)Declare a variable as an enumeration type (b)Use an enumeration as a parameter type (c)Use an integer in place of a constant defined by an enumeration (d)Store an enumeration in its own file
13. An enumeration inherits methods from which of the following classes? (a)java.lang.Object (b)java.lang.Enum (c)both a and b (d)neither a nor b
14. Which of the following is not true about static imports? (a)They let you import the static fields and methods of a class. (b)They let you import the constants of an enumeration. (c)They often make your code easier to read. (d)They reduce the amount of typing that’s required.
Explanation / Answer
1. Which of the following is not a reason to create a package? To prevent other developers from using the class
Package is used to store all the related class together so that we can reuse them later.
2. To include a class in a package, you (a)code an import statement as the first statement of the class
example : import java.util.*; --> it will import all the classes in java.util package
3. What must you do to use a class that you’ve stored in a package from another application? (b)Code an import statement for the class. (c)Copy the directories and files of the package to the root directory of the application. (d)Both b and c.
We can use both ways like if class is stored in package of other application then we can use import statement by giving pull path of package or copy all the files in your current project working directory
4. Which of the following is a benefit of using javadoc comments? (a)They make your classes easier to debug. (c)They make it easy for other programmers to learn about your class.
Java doc comments solve the purpose why use this feature. If your code is properly documented then other programmers can easily understand what you wrote and in case of errors anyone can easily debug. Although comments more useful for other programmers o understand
5. Which of the following is a valid javadoc comment?(b)/* Calculates the balance due */
6. You can use the javadoc tool to generate the documentation for (d)all of the above
7. Which of the following is not true about the documentation you generate using the javadoc tool?. (d)It lets you view classes by package.
8. Which of the following is an advantage of coding two or more classes in the same file? (d)It makes it easier to reuse a class.
We can code all the related class in same file so that we can reuse collectively later but it is not suggested method because it makes the code less readable. Even we code all the classes in same file but when we compile class file will create individually for the classes
9. Which of the following is not true about an inner class? (a)It can contain static variables and methods.
A regular inner class can not contain static variables or methods. Although It can access them
10. Which of the following is not true about a static inner class?. (c)It can access instance variables and methods of the outer class.
A static inner class can only contain insatnce variables and methods of outer class
11. Each constant within an enumeration is assigned (a)an integer value beginning with zero (b)an integer value beginning with one (c)the integer value you specify
I find the options confusing but in Enum by default constants are assigned value starting from 0 and then it increment by one of following constants. But you can give your explicit value like 1 and then next constant will get automatically assigned value 2.
12. Which of the following can you not do with an enumeration? Use an integer in place of a constant defined by an enumeration.
In java it is difficult to do that but there is way also but according to options this values suits only.
13. An enumeration inherits methods from which of the following classes? (a)java.lang.Object (b)java.lang.Enum (c)both a and b
all the enum class have one common class java.lang.Enum which inherits methods from java.lang.Object
14. Which of the following is not true about static imports? (c)They often make your code easier to read..
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.