Quiz 8
Wednesday
With a piece of paper, write down your name and answers to the following questions.
When a concrete class implements an interface, it must ________.
- overload all of the methods listed in the interface
- override all of the methods listed in the interface
- not have any constructors
- not have any fields
Abstract classes can ________.
- be used as superclasses
- be used as subclasses
- have instance fields
- All of the above
With the following inheritance hierarchy ...
... and the following variable declarations ...
Shape shape = new Shape(); Triangle triangle = new Triangle(); Rectangle rectangle = new Rectangle(); Square square = new Square();
... which one of the following will cause a compiler error?
shape = triangle
shape = square
square = null
square = rectangle
What is an abstract class?
- An abstract class is one without any derived classes.
- An abstract class is any superclass with more than one subclass.
- An abstract class is a class that contains abstract methods.
- An abstract class is another name for “base class.”
What must be true if a derived class of an abstract superclass does not override all of the superclass’s abstract methods?
- This is always an error on the subclass.
- This is always an error on the superclass.
- The derived class itself must be declared abstract.
- The derived class is automatically non-abstract, and this is OK.
Student Performance and Statistics
A histogram of student performance on percentage grades for Quiz 8 on Wednesday.
A table showing the average performance for each question in Quiz 8 on Wednesday.
Friday
With a piece of paper, write down your name and answers to the following questions.
All classes directly or indirectly inherit from one class. What is this class’s name?
- Super
- Object
- Root
- Java
Fields in an interface are ________.
final
static
- both
final
andstatic
- not allowed
With the following inheritance hierarchy ...
... which of the following array declarations is correct for an array that is expected to hold up to 10 objects of types
Shape
,Rectangle
, andSquare
?Rectangle[] array = new Rectangle[10]
Shape[] array = new Rectangle[10]
Shape[] array = new Shape[10]
Rectangle[] array = new Shape[10]
Here is an abstract method defined in a superclass:
public abstract int sum(int[] arrary);
Which of the following is required in a concrete subclass?
public abstract int sum(int[] array) {...}
public int sum(int[] array) {...}
public double int sum(int[] array) {...}
public int sum(long[] array) {...}
What is an abstract method?
- An abstract method is any method in an abstract class.
- An abstract method is a method that cannot be inherited.
- An abstract method is declared with the reserved word
abstract
, and it does not have a method body. - An abstract method is a method in the derived class that overrids a superclass method.
Student Performance and Statistics
A histogram of student performance on percentage grades for Quiz 8 on Friday.
A table showing the average performance for each question in Quiz 8 on Friday.