Questions: Abstract Classes and Interfaces

4 questions to test your understanding

Score: 0 / 4
Question 1 Multiple Choice

In Java, Shape is declared as `public abstract class Shape` with an abstract method area(). What happens with the statement `Shape s = new Shape();`?

AIt creates a Shape whose area() returns 0
BIt compiles, but calling s.area() throws an exception
CIt does not compile, because an abstract class cannot be instantiated
DIt creates an object of the first subclass of Shape
Question 2 Multiple Choice

Circle extends the abstract class Shape but does not provide a body for Shape's abstract method area(), and Circle is not itself marked abstract. What does the Java compiler do?

AIt reports an error, because a concrete class must implement every inherited abstract method
BIt accepts the class and uses an empty area() method
CIt accepts the class and makes area() return 0.0
DIt accepts the class but prevents Circle objects from calling area()
Question 3 True / False

A single Java class can implement more than one interface.

TTrue
FFalse
Question 4 Short Answer

You are designing classes Dog, Cat and Robot. All three must provide a method makeSound(). Dog and Cat also share name and age fields with identical code. Which tools would you use, and why?

Think about your answer, then reveal below.