Java Ch9

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

Java Quizzes & Trivia
Java ch9

  
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. 
     Which of the following statements is false? 
    • A. 

      A subclass is generally larger than its superclass.

    • B. 

      A superclass object is a subclass object.

    • C. 

      The class following the extends keyword in a class declaration is the direct superclass of the class being declared.

    • D. 

      Java uses interfaces to provide the benefits of multiple inheritance.


  • 2. 
     Inheritance is also known as the
    • A. 

      “knows-a” relationship.

    • B. 

      “has-a” relationship.

    • C. 

      “uses-a” relationship.

    • D. 

      “is-a” relationship.


  • 3. 
     Which of the following is not a superclass/subclass relationship?
    • A. 

      Ford/Taurus.

    • B. 

      University/Brown University

    • C. 

      Sailboat/Tugboat

    • D. 

      Country/USA


  • 4. 
    : An advantage of inheritance is that:
    • A. 

      All methods can be inherited

    • B. 

      All instance variables can be uniformly accessed by subclasses and superclasses.

    • C. 

      Objects of a subclass can be treated like objects of their superclass.

    • D. 

      None of the above.


  • 5. 
    Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method?
    • A. 

      base.

    • B. 

      This

    • C. 

      Public

    • D. 

      Super


  • 6. 
    Using the protected keyword gives a member:
    • A. 

      Public access.

    • B. 

      B. package access.

    • C. 

      C. private access.

    • D. 

      D. block scope.


  • 7. 
    Superclass methods with this level of access cannot be called from subclasses.
    • A. 

      A. private.

    • B. 

      B. public.

    • C. 

      C. protected.

    • D. 

      D. package.


  • 8. 
     Every class in Java, except ________, extends an existing class.
    • A. 

      A. Integer.

    • B. 

      B. Object.

    • C. 

      C. String.

    • D. 

      D. Class.


  • 9. 
    Overriding a method differs from overloading a method because:
    • A. 

      A. Overloaded methods have the same signature.

    • B. 

      B. Overridden methods have the same signature.

    • C. 

      C. Both of the above.

    • D. 

      D. Neither of the above.


  • 10. 
    9.4.2 Q1: To avoid duplicating code, use ________, rather than ________.
    • A. 

      A. inheritance, the “copy-and-past” approach.

    • B. 

      B. the “copy-and-past” approach, inheritance.

    • C. 

      C. a class that explicitly extends Object, a class that does not extend Object.

    • D. 

      D. a class that does not extend Object, a class that explicitly extends Object.


  • 11. 
    Consider the classes below, declared in the same file:class A {   int a;   public A()    {      a = 7;   }}class B extends A {   int b;   public B()    {b = 8;   }    }Which of the statements below is false?
    • A. 

      A. Both variables a and b are instance variables.

    • B. 

      B. After the constructor for class B executes, the variable a will have the value 7.

    • C. 

      C. After the constructor for class B executes, the variable b will have the value 8.

    • D. 

      D. A reference of type A can be treated as a reference of type B.


  • 12. 
    9.4.3 Q2: Which of the following is the superclass constructor call syntax?
    • A. 

      A. keyword super, followed by a dot (.) .

    • B. 

      B. keyword super, followed by a set of parentheses containing the superclass constructor arguments.

    • C. 

      C. keyword super, followed by a dot and the superclass constructor name.

    • D. 

      D. None of the above.


  • 13. 
    Which superclass members are inherited by all subclasses of that superclass?
    • A. 

      A. private instance variables and methods.

    • B. 

      B. protected instance variables and methods.

    • C. 

      C. private constructors.

    • D. 

      D. protected constructors.


  • 14. 
    9.4.4 Q2: Which statement is true when a superclass has protected instance variables?
    • A. 

      A. A subclass object can assign an invalid value to the superclass’s instance variables, thus leaving an object in an inconsistent state.

    • B. 

      B. Subclass methods are more likely to be written so that they depend on the superclass’s data implementation.

    • C. 

      C. We may need to modify all the subclasses of the superclass if the superclass implementation changes.

    • D. 

      D. All of the above.


  • 15. 
    9.4.5 Q1: private fields of a superclass can be accessed in a subclass
    • A. 

      A. by calling private methods declared in the superclass.

    • B. 

      B. by calling public or protected methods declared in the superclass.

    • C. 

      C. directly.

    • D. 

      D. All of the above.


  • 16. 
    Failure to prefix the superclass method name with the keyword super and a dot (.) separator when referencing the superclass’s method causes ________.
    • A. 

      A. a compile-time error.

    • B. 

      B. a syntax error.

    • C. 

      C. infinite recursion.

    • D. 

      D. a runtime error.


  • 17. 
    9.5 Q1: When a subclass constructor calls its superclass constructor, what happens if the superclass’s constructor does not assign a value to an instance variable?
    • A. 

      A. A syntax error occurs.

    • B. 

      B. A compile-time error occurs.

    • C. 

      C. A run-time error occurs.

    • D. 

      D. The program compiles and runs because the instance variables are initialized to their default values.


  • 18. 
    9.6 Q1: Which of the following statements is (are) true?A.    We can use inheritance to customize existing software.B.    A superclass specifies commonality.C.    A superclass can be modified without modifying subclassesD.    A subclass can be modified without modifying its superclass.
    • A. 

      A. All of the above.

    • B. 

      B. None of the above.

    • C. 

      C. A, B and C.

    • D. 

      D. A, B and D.


  • 19. 
    9.6 Q2: Which of the following is an example of a functionality that should not be “factored out” to a superclass?
    • A. 

      A. Both ducks and geese are birds that know how to start flying from the water.

    • B. 

      B. All vehicles know how to start and stop.

    • C. 

      C. All animals lay eggs, except for mammals.

    • D. 

      D. All paints have a color.


  • 20. 
    9.7 Q1: The default implementation of method clone of Object performs a ________.
    • A. 

      A. empty copy.

    • B. 

      B. deep copy.

    • C. 

      C. full copy.

    • D. 

      D. shallow copy.


  • 21. 
    9.7 Q2: The default equals implementation determines:
    • A. 

      A. whether two references refer to the same object in memory.

    • B. 

      B. whether two references have the same type.

    • C. 

      C. whether two objects have the same instance variables.

    • D. 

      D. whether two objects have the same instance variable values.


  • 22. 
    9.8 Q1: Class ________ represents an image that can be displayed on a JLabel.
    • A. 

      A. Image.

    • B. 

      B. Icon.

    • C. 

      C. ImageIcon.

    • D. 

      D. IconImage.


  • 23. 
    9.8 Q2: Which method changes the text the label displays?
    • A. 

      A. changeText.

    • B. 

      B. setText.

    • C. 

      C. changeLabel.

    • D. 

      D. setLabel.


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.