Let's look at few examples

Report a typo

Which of these are correct implementations of the given interface?

interface Animal {
    val numberOfLimbs: Int
    fun move()
    fun communicate()
}

  1. fun run() {}
    fun sayMeow() {}
    
    class Cat : Animal {
        override val numberOfLimbs: Int = 4
    
        override fun move() {
            run()
        }
        override fun communicate() {
            sayMeow()
        }
    }
  2. class Dog : Animal {
        override val numberOfLimbs: Int = 4
    
        override fun move() {
            run()
        }
    }
  3. fun howl(){}
    
    class Wolf : Animal {
        override fun move() {
            run()
        }
        override fun communicate() {
            howl()
        }
    }
  4. fun catchPrey(){}
    
    class Bear : Animal {
        override val numberOfLimbs: Int = 4
    
        override fun move() {
            run()
        }
        override fun communicate() {
            howl()
        }
    
        override fun eat()
        {
            catchPrey()
        }
    }
  5. fun burrow(){}
    
    class Fox : Animal {
        override val numberOfLimbs: Int = 4
    
        override fun move() {
            run()
        }
        override fun communicate() {
            howl()
        }
    
        fun digShelter() {
            burrow()
        }
    }

Select one or more options from the list
___

Create a free account to access the full topic