Java Interfaces vs. Abstract Classes: Key Differences & Examples πŸš—

Learn how to use abstract classes and interfaces in Java with clear examples. Understand their differences and when to choose each for your projects!

Java Interfaces vs. Abstract Classes: Key Differences & Examples πŸš—
Programming w/ Professor Sluiter
5.0K views β€’ Sep 20, 2019
Java Interfaces vs. Abstract Classes: Key Differences & Examples πŸš—

About this video

Examples of abstract classes compared and contrasted to interface classes in Java.

An abstract class defines a parent model. For example, a vehicle is an abstract idea. Cars, trucks, airplanes, bicycles are all implementations of the abstract idea of a vehicle. Another example is user account. There may be subclasses of the abstract such as admin account, student account, teacher account, customer account, sales person account. In a program, each of these types of accounts would share the same parent. The program could create instances of these account types but would never create an instance of the abstract class "user account". In Java, a class can inherit from only one parent. A class can implement many interfaces though.

An interface is like a blueprint for a class. An interface usually has a list of method names, but does not include any code. For example, an interface called "ManageData" might have the methods - readOneRecord, readAllRecords, writeOne, writeAll, deleteOne etc. Any class that implements the ManageData interface must have a method for readOneRecord, readAllRecords, writeOne, writeAll, deleteOne. We might have a class called FileIODataManager which uses text files to do all of these operations. Another class called DataBaseDataManger could also implement these same methods but would communicate with a mySQL database server to do the operations. The two classes have the exact same collection of method names but are doing the work in completely different ways.

This video is part of a series on Java programming.

Tags and Topics

Browse our collection to discover more content in these categories.

Video Information

Views

5.0K

Likes

87

Duration

12:54

Published

Sep 20, 2019

User Reviews

4.6
(4)
Rate:

Related Trending Topics

LIVE TRENDS

Related trending topics. Click any trend to explore more videos.