Java for Humans {Abstract Classes & Interfaces}

Lincoln W Daniel
ModernNerd Code
Published in
8 min readJan 18, 2016

--

View Table of Contents | Download Supporting Code | Subscribe to ModernNerd Youtube Channel for Coding Videos | By Lincoln W Daniel

In the Class Inheritance chapter, we learned about forming a contract between classes, superclasses, and users. By creating subclasses that share a superclass, we can share fields and methods between them to decrease the amount of code we write, create a predictable interface for users, and employ polymorphism. In this chapter, we will learn how to make our contracts better through abstract classes and interfaces.

Why Abstract Classes & Interface are Important & Useful

A regular class defines the fields, implements fully functioning methods and can be instantiated; such a class is referred to as a concrete class. That is the vast majority of classes you will write and use in your programming career. Abstract classes and interfaces cannot be instantiated, but they, too, define fields and methods — although they may not implement methods. They are best for forming a contract between a class, its subclasses, and users of its subclasses.

Abstract Class

An abstract class is much like a regular class in that it can have fields and methods. What makes it special is its methods may or may not have bodies. That means an abstract class can have method signatures that are declared as abstract as well as full methods as usual.

--

--

Lincoln W Daniel
ModernNerd Code

Chief Bull @ BullAcademy.org ® Elevating writers @ ManyStories.com. Author @JavaForHumans Ex: Editor in Chief MarkGrowth (acq.), Engineer @Medium @GoPuff