Giter Site home page Giter Site logo

cardealership's Introduction

Polymorphism & Composition Homework - Quiz

Polymorphism

  1. What does the word 'polymorphism' mean?

    a. Polymorphism (in computing) means applying the same functionality to different data types.

  2. What does it mean when we apply polymorphism to OO design? Give a simple Java example.

    a. Polymorphism is exclusive to OOP in the sense that classes are data types with their own functionality. Through polymorphism, it is possible to use the same methods on multiple instances of each class - even if they have different properties.

    Run CarTest.java and notice that tankIsCar() passes

  3. What can we use to implement polymorphism in Java?

    a. In the example, the class Tank is interfaced with the abstract class Car through IDrive.

  4. How many 'forms' can an object take when using polymorphism?

    a. The number of forms that any particular object can take is equivalent to the number of methods each class is required to share.

  5. Give an example of when you could use polymorphism.

    a. In the example, polymorphism allows Car to have a damage property, while Tank does not, they still share the same method drive() through their interface.

Composition

  1. What do we mean by 'composition' in reference to object-oriented programming?

    a. Composition means that classes contain instances of other classes which have desired functionaliy.

  2. When would you use composition? Provide a simple example in Java.

    a. In the example, Car has the drive() method which is shared by each of its children through IDrive.

    Notice that carsCanDrive() passes in CarTest

  3. What is/are the advantage(s) of using composition?

    a. Composition allows for each class which implements IDrive to use drive().

  4. When an object is destroyed, what happens to all the objects it is composed of?

    a. If the object being destroyed is a child of an abstract class then there is no effect on the parent. If the object being destroyed is a parent, the child will not have access to its methods or properties.

cardealership's People

Contributors

ewan88 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.