When to use an abstract class in Java - 038

Опубликовано: 03 Ноябрь 2015
на канале: Deege
124,973
2.4k

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-...

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

Social Links: Don't hesitate to contact me if you have any further questions.
WEBSITE : [email protected]
TWITTER :   / deege  
FACEBOOK:   / deegeu.programming.tutorials  
GOOGLE+ : http://google.com/+Deegeu-programming...

Hosted by DJ Spiess
About Me: http://www.deegeu.com/about-programmi...

Related Videos:

What are static factory methods in Java? - 036
   • What are static factory methods in Ja...  

Free Java Course Online
   • What important Java Terms do I need t...  

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/...)
Source: http://incompetech.com/music/royalty-...
Artist: http://incompetech.com/