CSCI 2010 - QUIZ 4 QUESTIONS AND VERIFIED
ANSWERS
Which of the following is allowed in a Java interface? - Answers - Heading for public
methods.
Given an interface called Pourable, how should an interface called Drinkable de
declared so it inherits all of the methods header from Pourable and adds some
additional methods headers? - Answers - public class Drinkable extends Pourable
Where should the keyword abstract be used in a class definition for an abstract class? -
Answers - Both of the above.
Given the following class definitions:
public class Carnivore{
public Carnivore() {}
public void speak() {System.out.println("Grrr"); }
}
public class Cat extends Carnivore {
public Cat() {}
public void speak() {System.out.println("Meow"); }
}
What output will the following statements generate?
Carnivore runTumTugger = new Carnivore();
Carnivore bombalurina = new Cat();
Cat munkustap = new Cat();
runTumTugger.speak();
bombalurina.speak();
munkustrap.speak(); - Answers - Grr
Meow
Meow
What is the difference between inheritance and polymorphism? - Answers - Inheritance
means that methods written in a base class can be applied to objects of a derived class.
Polymorphism means that methods written in a derived class can be applied to objects
of the base class.
ANSWERS
Which of the following is allowed in a Java interface? - Answers - Heading for public
methods.
Given an interface called Pourable, how should an interface called Drinkable de
declared so it inherits all of the methods header from Pourable and adds some
additional methods headers? - Answers - public class Drinkable extends Pourable
Where should the keyword abstract be used in a class definition for an abstract class? -
Answers - Both of the above.
Given the following class definitions:
public class Carnivore{
public Carnivore() {}
public void speak() {System.out.println("Grrr"); }
}
public class Cat extends Carnivore {
public Cat() {}
public void speak() {System.out.println("Meow"); }
}
What output will the following statements generate?
Carnivore runTumTugger = new Carnivore();
Carnivore bombalurina = new Cat();
Cat munkustap = new Cat();
runTumTugger.speak();
bombalurina.speak();
munkustrap.speak(); - Answers - Grr
Meow
Meow
What is the difference between inheritance and polymorphism? - Answers - Inheritance
means that methods written in a base class can be applied to objects of a derived class.
Polymorphism means that methods written in a derived class can be applied to objects
of the base class.