From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Using abstract classes and methods

Using abstract classes and methods - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Using abstract classes and methods

- When designing an object-oriented, contract-based programming architecture, you can frequently choose between using interfaces and abstract classes. An abstract class is abstract because you add the abstract keyword and then it can contain a mixture of fully implemented methods and abstract methods. An abstract method is just like a method in an interface. It doesn't have an implementation. It just indicates the method signature and then any subclasses of an abstract method must implement that method. In this project, the Olive class is the superclass for two subclasses, Ligurian and Kalamata. I'm going to change this class and make it abstract by adding the abstract keyword after public and before the keyword class. Now that doesn't change any behavior on its own. I'll run the application and show that everything still works. But now, I'll declare an abstract method as part of this class. I'll place this new method down here after all the setters and getters, but before toString…

Contents