Which of the following is allowed in a Java interface?
Headings for public methods.
Given an interface called Pourable, how should an interface called Drinkable be declared so it inherits all of the methods headers from Pourable and adds some additional method headers?
public class Drinkable extends Pourable
Where should the keyword abstract
be used in a class definition for an abstract class?
Both of the above.
Given the following class definitions:
1
2
3
4
5
6
7
8
9
public class Carnivore {
public Carnivore() {}
public void speak() { System.out.println("Grrr"); }
}
public class Cat extends Carnivore {
public Car() {}
public void speak() { System.out.println("Meow"); }
}
What output will the following statements generate?
1
2
3
4
5
6
7
Carnivore rumTumTugger = new Carnivore();
Carnivore bombalurina = new Cat();
Cat munkustrap = new Cat ();
rumTumTugger.speak();
bombalurina.speak();
munkustrap.speak();
1 2 3 Grrr Meow Meow
What is the difference between inheritance and polymorphism?
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.
How should a class called Philosopher
be declared so that it is derived from the base class Person
and implements the interface Reasonable
?
1 public class Philosopher extends Person implements Reasonable
Which of the following method headers must be implemented in any class that implements the Comparable
interface?
1 public int compareTo(Object other);
A class can only implement one interface.
False
What is the difference between an abstract class and an interface?
An abstract class can contain method definitions while an interface can only contain method headers.
Java uses static binding to determine which version of a method is called on an object.
False
You cannot create an object of an abstract class.
True
An interface can contain public name constants.
True