nerdexam
Microsoft

98-361 · Question #259

The Dog class and the Cat class inherit from the Animal class. The Animal class includes a breathe() method and a speak() method. If the speak() method is called from an object of type Dog, the…

The correct answer is C. polymorphism. Polymorphism is often referred to as the third pillar of object-oriented programming, after encapsulation and inheritance. Polymorphism is a Greek word that means "many-shaped" and it has two distinct aspects: At run time, objects of a derived class may be treated as objects of…

Understanding Object-Oriented Programming

Question

The Dog class and the Cat class inherit from the Animal class. The Animal class includes a breathe() method and a speak() method. If the speak() method is called from an object of type Dog, the result is a bark. If the speak() method is called from an object of type Cat, the result is a meow. Which term is used to describe this object-oriented concept?

Options

  • Amultiple inheritance
  • Bencapsulation
  • Cpolymorphism
  • Ddata hiding

How the community answered

(17 responses)
  • A
    6% (1)
  • B
    18% (3)
  • C
    71% (12)
  • D
    6% (1)

Explanation

Polymorphism is often referred to as the third pillar of object-oriented programming, after encapsulation and inheritance. Polymorphism is a Greek word that means "many-shaped" and it has two distinct aspects: * At run time, objects of a derived class may be treated as objects of a base class in places such as method parameters and collections or arrays. When this occurs, the object's declared type is no longer identical to its run-time type. * Base classes may define and implement virtual methods, and derived classes can override them, which means they provide their own definition and implementation. At run-time, when client code calls the method, the CLR looks up the run-time type of the object, and invokes that override of the virtual method. Thus in your source code you can call a method on a base class, and cause a derived class's version of the method to be executed.

Topics

#polymorphism#inheritance#method overriding#OOP concepts

Community Discussion

No community discussion yet for this question.

Full 98-361 Practice