CIS 212 Test 2 - Polymorphism

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Xenonii
X
Xenonii
Community Contributor
Quizzes Created: 4 | Total Attempts: 974
Questions: 7 | Attempts: 328

SettingsSettingsSettings
Polymorphism Quizzes & Trivia

A quick test on Polymorphism for CIS 212


Questions and Answers
  • 1. 

    What is the actual type of an object?

    • A.

      The super class of the object

    • B.

      The concrete class used to create the object

    • C.

      The abstract class of an object

    • D.

      The inheritance hierarchy of the object

    Correct Answer
    B. The concrete class used to create the object
    Explanation
    The actual type is determined during the construction of an object

    Rate this question:

  • 2. 

    What is the apparent type of an object?

    • A.

      The type of the expression that uses the object

    • B.

      The result of the toString() method

    • C.

      The subtype of the object

    • D.

      The class used to instantiate the object

    Correct Answer
    A. The type of the expression that uses the object
    Explanation
    E.g. Collection c = new Vector();
    c has an apparent type as a Collection, but the actual type is Vector

    Rate this question:

  • 3. 

    An apparent type is always...

    • A.

      A subtype of the actual type

    • B.

      The same for each instance

    • C.

      A supertype of the actual type

    • D.

      None of the above

    Correct Answer
    C. A supertype of the actual type
    Explanation
    Remember that a type includes itself as a supertype

    Rate this question:

  • 4. 

    When using an object, the interface is defined by the

    • A.

      Apparent type

    • B.

      Actual type

    • C.

      None of the above

    Correct Answer
    A. Apparent type
    Explanation
    The interface of an object is defined by its apparent type, which is the type that is declared and known at compile-time. This is the type that determines which methods and properties can be accessed on the object. The actual type of an object, on the other hand, refers to the specific class or type that the object belongs to at runtime. While the actual type may be different from the apparent type in cases of inheritance or polymorphism, it does not affect the interface of the object. Therefore, the correct answer is apparent type.

    Rate this question:

  • 5. 

    When using an object, the behaviour is defined by the

    • A.

      Apparent type

    • B.

      Actual type

    • C.

      None of the above

    Correct Answer
    B. Actual type
    Explanation
    When using an object, the behavior is defined by its actual type. This means that the object will exhibit the specific behaviors and functionalities that are defined in its actual class or type. The apparent type of an object refers to the type that is used to reference the object, but it does not determine the behavior of the object itself. Therefore, the actual type of an object is what ultimately defines its behavior.

    Rate this question:

  • 6. 

    Substitution principle means that

    • A.

      We can swap an instance of some type with some other instance of the same type

    • B.

      Subtype can be used wherever a supertype is expected without affecting correctness of client code

    • C.

      Supertype can be used wherever a subtype is expected without affecting correctness of client code

    • D.

      We can override a method easily

    • E.

      None of the above

    Correct Answer
    B. Subtype can be used wherever a supertype is expected without affecting correctness of client code
    Explanation
    The correct answer is that the substitution principle means that a subtype can be used wherever a supertype is expected without affecting the correctness of client code. This principle is a fundamental concept in object-oriented programming, where it allows for polymorphism and code reusability. By substituting a subtype for a supertype, we can write code that is more flexible and adaptable to different types of objects, without needing to modify the client code. This ensures that the client code will still work correctly, regardless of the specific subtype being used.

    Rate this question:

  • 7. 

    When creating a subtype, Java cannot enforce some specification declared in some supertype. So in order for the subtype to be compliant with the spec, it should

    • A.

      Implement all methods of the supertype

    • B.

      Satisfy the postconditions and preconditions found in the spec

    • C.

      Inherit by specification

    • D.

      None of the above

    Correct Answer
    B. Satisfy the postconditions and preconditions found in the spec
    Explanation
    When creating a subtype in Java, it is important for the subtype to satisfy the postconditions and preconditions found in the specification of the supertype. This means that the subtype should adhere to the requirements and constraints set by the supertype, ensuring that it behaves correctly and consistently with the expected behavior. By satisfying the postconditions and preconditions, the subtype can ensure that it is compliant with the specification and can be used interchangeably with the supertype without causing any unexpected issues or errors.

    Rate this question:

Related Topics

Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.