When to Use Abstract Classes in Java ๐Ÿ› ๏ธ

Learn when to use abstract classes in Java to define incomplete classes with shared behavior, using the 'abstract' keyword.

When to Use Abstract Classes in Java ๐Ÿ› ๏ธ
Deege
125.7K views โ€ข Nov 3, 2015
When to Use Abstract Classes in Java ๐Ÿ› ๏ธ

About this video

In Java, an abstract class is a class definition where we don't provide all the implementation details. The class has the keyword "abstract" added to it here. We denote abstract classes in our diagrams by making the class name in italics.

We can also mark some of the methods as abstract. That means we just provide the method signature and return type, but we don't provide the Java block that implements the method. We mark the methods with the keyword "abstract". Note the method has no braces, no implementation, and just ends with a semi-colon. Again we use italics for abstract methods in our diagrams.

If we declare a class as abstract, the methods may or may not be abstract. We don't need to have any abstract methods. It would be weird, because what would be the point, but we can do it. The opposite isn't true. If we mark any method as abstract, we must mark the class as abstract.

Another note. We canโ€™t have a method that is abstract and private. We couldnโ€™t access it, and thereโ€™s really no point. If youโ€™re protecting it for subclasses, youโ€™ll want to use protected.

#java #programming #tutorial

โ–ผ
Like the video? Don't forget to subscribe! โžœ http://www.deegeu.com/subscribe

โ–ผ
Keep up to date with the newsletter! โžœ http://www.deegeu.com/newsletter/

Transcript and code: : http://www.deegeu.com/when-to-use-an-abstract-class-in-java/

Concepts: Java, classes, abstract classes, Compile-time safety

Social Links: Don't hesitate to contact me if you have any further questions.
WEBSITE : dj@deegeu.com
TWITTER : http://www.twitter.com/deege
FACEBOOK: https://www.facebook.com/deegeu.programming.tutorials
GOOGLE+ : http://google.com/+Deegeu-programming-tutorials

Hosted by DJ Spiess
About Me: http://www.deegeu.com/about-programming-tutorial-videos/

Related Videos:

What are static factory methods in Java? - 036
https://youtu.be/sOpbAOX5nJs

Free Java Course Online
https://www.youtube.com/watch?v=yxwdKX7ErJ4&list=PLZlGOBonMjFVq9FF0eiS_emcFmP-0fSBe

Media credits: All images are owned by DJ Spiess unless listed below:

Cookies
https://videos.pexels.com under CC0

Music
Easy Jam by Kevin MacLeod is licensed under a Creative Commons Attribution license (https://creativecommons.org/licenses/by/4.0/)
Source: http://incompetech.com/music/royalty-free/index.html?isrc=USUAN1100245
Artist: http://incompetech.com/

Tags and Topics

Browse our collection to discover more content in these categories.

Video Information

Views

125.7K

Likes

2.5K

Duration

4:26

Published

Nov 3, 2015

User Reviews

4.7
(25)
Rate:

Related Trending Topics

LIVE TRENDS

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

Trending Now