1. Define the term abstract class in your own words. 2. Can an abstract class be
ID: 3727221 • Letter: 1
Question
1. Define the term
abstract class
in your own words.
2. Can an abstract class be instantiated? For example, if we have an abstract class Animal,
can we instantiate it in our main program by saying something like this?
Animal fuzzyAnimal = new Animal();
3. Can a class be abstract even if you don’t include the reserved word abstract in the class
header?
4. What are some ways that abstract classes and interfaces are different?
5. What are some ways that abstract classes and interfaces are similar?
6. What is meant by the term “single inheritance”?
7. How does single inheritance fuel the need for Java to include both abstract classes and
interfaces (as opposed to one or the other)?
8. Suppose that you write code (say a Cat class) that extends an abstract class (say an
Animal class) and you don’t override the abstract methods. What will happen when you
compile your code?
9. What’s the benefit to using an abstract class in a programming solution?
10. Suppose that you write code for an interface (say the interface Valuable) and include a
full method implementation in the interface code. What will happen when you compile
your code?
11. Suppose that you write code for an interface (say the interface Valuable) and then you
implement the interface in a concrete class (say a class Gold). What happens if you don’t
provide the full method implementation for all of the methods specified by the interface?
Explanation / Answer
1A:
2A:
3A:
4A:
Can contain both abstract and non abstract methods. To make a method abstract,
we need use abstract keyword in the method declaration.
5A:
Below are few similarities between Abstract class and Interface,
6A:
7A:
8A:
9A:
10A: Compiler will throw error.
11A: Compiler will throw error.
Abstract Class Interfaces abstract keyword is used to make abstract class. Interface keyword will be used to create an interface.Can contain both abstract and non abstract methods. To make a method abstract,
we need use abstract keyword in the method declaration.
All the methods will be abstract(In latest java versions can have static methods as well) Doen't support multiple inheritance supports multiple inheritance Abstract class can have final, non-final, static and non-static variables. Interface has only static and final variables.Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.