From the course: Java Object-Oriented Programming

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Using abstract classes in Java to reduce code complexity

Using abstract classes in Java to reduce code complexity - Java Tutorial

From the course: Java Object-Oriented Programming

Using abstract classes in Java to reduce code complexity

- [Instructor] An abstract class allows us to add abstraction to our Java programs. It's like a template for a class where some of the functionality is not implemented yet. This means you cannot instantiate an abstract class but other classes can extend the abstract class and implement the appropriate functionality. One way we might use abstract classes in Java is for reading a file. Let's say you want to read a file in several different ways. Some hold secret messages, some have information we want to redact. So it's important to be able to retrieve the contents of a file in different ways. To start off, we'll create an abstract file reader class. This class will have the basic operations for interacting with the file and retrieving the files contents. It will also have one attribute called file path. It will have the data type path which is built into Java. Once it's set, it will not change for the instance. So that's…

Contents