Ch8 Java

38 Questions  I  By Bing22
Please take the quiz to rate it.

Java Quizzes & Trivia

  
Changes are done, please start the quiz.


Questions and Answers

Removing question excerpt is a premium feature

Upgrade and get a lot more done!
  • 1. 
    8.2 Q1: The _________ of a class are also called the public services or the public interface that the class provides to its clients.
    • A. 

      Public constructors.

    • B. 

      public instance variables.

    • C. 

      public methods

    • D. 

      All of the above.


  • 2. 
    The static method ________ of class String returns a formatted String.
    • A. 

      Printf

    • B. 

      Format

    • C. 

      FormatString

    • D. 

      ToFormatString


  • 3. 
    Which statement is false?
    • A. 

      The actual data representation used within the class is of no concern to the class’s clients

    • B. 

      Clients generally care about what the class does but not how the class does it

    • C. 

      Clients are usually involved in a class’s implementation

    • D. 

      Hiding the implementation reduces the possibility that clients will become dependent on class-implementation details


  • 4. 
    Which of the following should usually be private?
    • A. 

      Methods.

    • B. 

      Constructors

    • C. 

      Variables (or fields).

    • D. 

      All of the above.


  • 5. 
    Which of the following statements is true?
    • A. 

      Methods and instance variables can both be either public or private.

    • B. 

      Information hiding is achieved by restricting access to class members via keyword public.

    • C. 

      The private members of a class are directly accessible to the client of a class.

    • D. 

      None of the above is true.


  • 6. 
    When should a program explicitly use the this reference?
    • A. 

      Accessing a private variable

    • B. 

      Accessing a public variable

    • C. 

      Accessing a local variable.

    • D. 

      Accessing a field that is shadowed by a local variable


  • 7. 
    Having a this reference allows:
    • A. 

      A method to refer explicitly to the instance variables and other methods of the object on which the method was called.

    • B. 

      A method to refer implicitly to the instance variables and other methods of the object on which the method was called.

    • C. 

      An object to reference itself.

    • D. 

      All of the above.


  • 8. 
     A constructor cannot:
    • A. 

      Be overloaded.

    • B. 

      Initialize variables to their defaults.

    • C. 

      Specify return types or return values.

    • D. 

      Have the same name as the class.


  • 9. 
    8.5 Q2: Constructors:
    • A. 

      Initialize instance variables.

    • B. 

      When overloaded, can have identical argument lists.

    • C. 

      When overloaded, are selected by number, types and order of types of parameters.

    • D. 

      A and c.


  • 10. 
     A programmer-defined constructor that has no arguments is called a ________.
    • A. 

      Zero-argument constructor.

    • B. 

      No-argument constructor.

    • C. 

      Default constructor

    • D. 

      Main constructor.


  • 11. 
     What happens when this is used in a constructor’s body to call another constructor of the same class if that call is not the first statement in the constructor?
    • A. 

      A compilation error occurs.

    • B. 

      A runtime error occurs.

    • C. 

      A logic error occurs.

    • D. 

      Nothing happens. The program compiles and runs.


  • 12. 
    When implementing a method, use the class’s set and get methods to access the class’s ________ data.
    • A. 

      Public

    • B. 

      Private

    • C. 

      Protected

    • D. 

      All of the above


  • 13. 
    Which statement is false?
    • A. 

      The compiler always creates a default constructor for a class.

    • B. 

      If a class’s constructors all require arguments and a program attempts to call a no-argument constructor to initialize an object of the class, a compilation error occurs.

    • C. 

      A constructor can be called with no arguments only if the class does not have any constructors or if the class has a public no-argument constructor

    • D. 

      None.


  • 14. 
    Set methods are also commonly called ________ methods and get methods are also commonly called ________ methods.
    • A. 

      Query, mutator.

    • B. 

      Accessor, mutator.

    • C. 

      Mutator, accessor.

    • D. 

      Query, accessor.


  • 15. 
    Using public set methods provides data integrity if:
    • A. 

      The instance variables are public.

    • B. 

      The instance variables are private

    • C. 

      The methods perform validity checking

    • D. 

      Both b and c.


  • 16. 
     Composition is sometimes referred to as a(n) ________.
    • A. 

      Is-a relationship.

    • B. 

      Has-a relationship.

    • C. 

      Many-in-one relationship.

    • D. 

      One-to-many relationship


  • 17. 
    : enum types are implicitly ________ and enum constants are implicitly ________.
    • A. 

      Final, static.

    • B. 

      Static, static.

    • C. 

      Static, final.

    • D. 

      Final, final


  • 18. 
     Which statement is false?
    • A. 

      An enum declaration is a comma-separated list of enum constants and may optionally include other components of traditional classes, such as constructors, fields and methods

    • B. 

      Any attempt to create an object of an enum type with operator new results in a compilation error.

    • C. 

      An enum constructor cannot be overloaded

    • D. 

      An enum constructor can specify any number of parameters


  • 19. 
    Which method returns an array of the enum’s constants?
    • A. 

      Values

    • B. 

      GetValues

    • C. 

      Constants

    • D. 

      GetConstants


  • 20. 
    Which of the following is false?
    • A. 

      Method finalize does not take parameters and has return type void.

    • B. 

      Memory leaks using Java are rare because of automatic garbage collection

    • C. 

      Objects are marked for garbage collection by method finalize.

    • D. 

      The garbage collector reclaims unused memory


  • 21. 
    Static class variables:
    • A. 

      Are final.

    • B. 

      Are public

    • C. 

      Are private

    • D. 

      Are shared by all objects of a class


  • 22. 
    Which of the following is false?
    • A. 

      A static method must be used to access private static instance variables

    • B. 

      A static method has no this reference

    • C. 

      A static method can be accessed even when no objects of its class have been instantiated

    • D. 

      A static method can call instance methods directly


  • 23. 
     Which syntax imports all static members of class Math?
    • A. 

      Static import java.lang.Math.*.

    • B. 

      Import static java.lang.Math.*.

    • C. 

      static import java.lang.Math

    • D. 

      Import static java.lang.Math


  • 24. 
     Instance variables declared final do not or cannot:
    • A. 

      Cause syntax errors if used as a left-hand value.

    • B. 

      Be initialized

    • C. 

      Be modified

    • D. 

      None


  • 25. 
    A final field should also be declared ________ if it is initialized in its declaration.
    • A. 

      Private

    • B. 

      Public

    • C. 

      Protected

    • D. 

      Static


  • 26. 
     Java programmers do not focus on:
    • A. 

      Crafting new classes and reusing existing classes.

    • B. 

      Understanding class library implementations

    • C. 

      Carefully testing classes they design

    • D. 

      Carefully documenting classes they design


  • 27. 
     Which of the following does not contribute to improved software reusability?
    • A. 

      Quickly creating new class libraries without testing them thoroughly

    • B. 

      Licensing schemes and protection mechanisms

    • C. 

      Descriptions of classes that allow programmers to determine whether a class fits their needs

    • D. 

      Cataloging schemes and browsing mechanisms


  • 28. 
    Abstract Data Types:
    • A. 

      Elevate the importance of data

    • B. 

      Are only approximations or models of real-world concepts and behaviors

    • C. 

      Capture two notions, data representation and operations

    • D. 

      All of the above.


  • 29. 
     The term “information hiding” refers to:
    • A. 

      Public methods

    • B. 

      Hiding implementation details from clients of a class

    • C. 

      Accessing static class members

    • D. 

      The process of releasing an object for garbage collection


  • 30. 
    A package is:
    • A. 

      A directory structure used to organize classes and interfaces.

    • B. 

      A mechanism for software reuse

    • C. 

      A group of related classes and interfaces

    • D. 

      All


  • 31. 
     A class within a package must be declared public if
    • A. 

      It will be used only by other classes in the same package

    • B. 

      It will be used by classes that are not in the same package

    • C. 

      It is in the same directory as the other classes in the package.

    • D. 

      It has a unique name


  • 32. 
     Consider the statement    package com.deitel.jhtp6.ch08;    Which of the following is true?
    • A. 

      The statement declares a package that exists at deitel.com

    • B. 

      The statement uses the Sun Microsystems convention of package naming

    • C. 

      The statement should be placed inside the class declaration

    • D. 

      The statement will generate a compile time error


  • 33. 
    When compiling a class in a package, the javac command-line option ________ causes the javac compiler to create appropriate directories based on the class’s package declaration.
    • A. 

      -p.

    • B. 

      -a.

    • C. 

      -d.

    • D. 

      -dir.


  • 34. 
    The import declaration import java.util.*; is known as a ________.
    • A. 

      Single-type-import declaration.

    • B. 

      All-type-import declaration

    • C. 

      Multiple-import declaration

    • D. 

      Type-import-on-demand declaration


  • 35. 
     The import declaration import *; ________.
    • A. 

      Causes a compilation error

    • B. 

      Imports all classes in the library.

    • C. 

      Imports the default classes in the library

    • D. 

      Imports the classes in package java.lang


  • 36. 
    The classpath consists of a list of directories or archive files, each separated by a ________ on Windows or a ________ on UNIX/Linux/Max OS X.
    • A. 

      Colon (:), semicolon (;).

    • B. 

      Semicolon (;), colon (:).

    • C. 

      Comma (,), semicolon (;).

    • D. 

      Semicolon (;), comma (,).


  • 37. 
     By default, the classpath consists only of the ________. However, the classpath can be modified by providing the ________ option to the javac compiler.
    • A. 

      Root directory of the package, -d.

    • B. 

      Current directory, -d.

    • C. 

      Root directory of the package, -classpath

    • D. 

      Current directory, -classpath.


  • 38. 
    When no access modifier is specified for a method or variable, the method or variable:
    • A. 

      Is public

    • B. 

      Is private

    • C. 

      Has package access

    • D. 

      Is static


Back to top

Removing ad is a premium feature

Upgrade and get a lot more done!
Take Another Quiz
We have sent an email with your new password.