When to use an abstract class in Java - 038

  Рет қаралды 125,005

Deege

Deege

Күн бұрын

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! ➜ www.deegeu.com/...

Keep up to date with the newsletter! ➜ www.deegeu.com/...
Transcript and code: : www.deegeu.com/...
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 : / deege
FACEBOOK: / deegeu.programming.tut...
GOOGLE+ : google.com/+Dee...
Hosted by DJ Spiess
About Me: www.deegeu.com/...
Related Videos:
What are static factory methods in Java? - 036
• What are static factor...
Free Java Course Online
• What important Java Te...
Media credits: All images are owned by DJ Spiess unless listed below:
Cookies
videos.pexels.com under CC0
Music
Easy Jam by Kevin MacLeod is licensed under a Creative Commons Attribution license (creativecommon...)
Source: incompetech.com...
Artist: incompetech.com/

Пікірлер: 96
@motorheadbanger90
@motorheadbanger90 3 жыл бұрын
62 people failed their Intro to Object Oriented Programming class... Bravo, excellent video. Using cooking recipes to explain Abstract classes is my most favorite way to describe them to the person who's interviewing me
@thomasl863
@thomasl863 4 жыл бұрын
This was the clearest explanation of any java concept I’ve ever seen in 4 minutes. Subscribing immediately
@jasper5016
@jasper5016 6 жыл бұрын
I cannot believe that these great tutorials have really low number of subscribers. I am not even a Java person but I visit these videos to learn basic concepts. Great. Thanks.
@danielchoi4202
@danielchoi4202 8 жыл бұрын
Awesome awesome awesome. Seriously, your tutorials are the only ones that I, or any beginner programmers, can understand. I can also tell that you put a ton of effort into editing. Thank you so much!
@SirGibbels
@SirGibbels 4 жыл бұрын
Came here to find out about JAVA, ended up discovering something far more important about bread...
@koriander.k7377
@koriander.k7377 3 жыл бұрын
@Saint Lochlan go fuck yourself bud.
@vickyanand5898
@vickyanand5898 3 жыл бұрын
Came here to find out about JAVA, ended up discovering this piece of art !
@ankitraj163
@ankitraj163 3 жыл бұрын
Haha....same here....the altitude thing
@colletteso-noon3844
@colletteso-noon3844 2 жыл бұрын
Thoses videos are great, they are dynamic and slow enough to understand
@tobicipher9300
@tobicipher9300 2 жыл бұрын
My teacher doesnt teach us why we use certain things in Java so this is very useful, thank you for the simply and clear explanation!
@MR-yc3my
@MR-yc3my 4 жыл бұрын
I kind of like when he stumbles through a word every now and then, but then he just keeps going. Shows confidence.
@FarizDarari
@FarizDarari 2 жыл бұрын
Many thanks! Stay healthy, stay happy, Teacher!
@ayushimathur27
@ayushimathur27 2 жыл бұрын
Thank you so much!! I have gone through a lot of videos but i was really confused, now I finally understand. 😊
@guruprasad6982
@guruprasad6982 6 жыл бұрын
we can implement the methods using interface as well? I just wanted to know why abstract class should be chosen if we have interface?
@shaun1114
@shaun1114 3 жыл бұрын
THIS WAS AN AMAZING EXPLANATION. Thanks
@Ali-mi9up
@Ali-mi9up 5 жыл бұрын
What an absolutely awesome tutorial. Deege U does it again!
@fallartifact8904
@fallartifact8904 6 жыл бұрын
Didn't know Mike from Breaking Bad did Java tutorials...
@arthurbm32
@arthurbm32 5 жыл бұрын
And he makes cookies hahaha
@vickyanand5898
@vickyanand5898 3 жыл бұрын
Now say my name !
@lucasmelo010
@lucasmelo010 6 жыл бұрын
Very well explained in less than 5 minutes. Thanks!
@bengrzybowski7671
@bengrzybowski7671 2 жыл бұрын
Very concise. thank you.
@palkia1416
@palkia1416 7 жыл бұрын
nice explanation, also the song is great
@bishalkumar3979
@bishalkumar3979 8 жыл бұрын
what is the use of constructors in an abstract class if we don't intend to have an object ? Will you please provide a detailed discussion on this topic ?
@deegeu
@deegeu 8 жыл бұрын
Your abstract class might still require some initialization. The constructor is used to initialize the class instance, and says nothing about if the class is abstract or concrete.
@jasper5016
@jasper5016 6 жыл бұрын
Can you please explain interfaces in more detail? I have seen your youtube video on Interfaces but I am not able to understand when to use Interfaces.
@ciaranmckenna5034
@ciaranmckenna5034 7 жыл бұрын
Including some live code would really improve this video, thanks for sharing though.
@HernisQ
@HernisQ 6 жыл бұрын
Thank you for your video! I have a question. I want a simple employee hierarchy where testers, developers and designers, among others in the future, are all employees, and all employees have unique IDs and a state (meeting, working, break, etc...), among others, which could be modelled as abstract class with protected attributes and some methods, abstract and otherwise. In this case, it is better to go with abstract classes instead of interfaces since we need a state, that is going to be shared by all possible subclass instances of an employee; and there is no such a thing as a generic employee, which goes hand in hand with not being able to instantiate an employee directly. I'd appreciate any thoughts on this. Thanks!
@lil_jeke
@lil_jeke 2 жыл бұрын
But you didn’t answer when to use abstract classes and when not to use them?
@michaelsteinberg3272
@michaelsteinberg3272 6 жыл бұрын
Finally an explanation that made sense 👍
@viplovedev
@viplovedev 7 жыл бұрын
Suppose I have - an interface with all the methods declared as those declared abstract in the abstract class - a concrete class which has all the concrete methods defined in the abstract class Now, I wish to put the same compile time safety and concrete implementations sharing while implementing a child class. Can I replace the abstract class with the combination of the interface and the concrete class? i.e., Replace "public class ChildClass extends AbstractClass" with "public class ChildClass implements TheInterface extends Concrete Class"
@pimpvader2430
@pimpvader2430 Жыл бұрын
Hi i hope somebody sees this because the video ist 7 Years old now. I am fairly new to Programming and my Question is why not just use an Interface? Why an abstract Class?
@harisharthanari7383
@harisharthanari7383 5 жыл бұрын
Interface or abstract class ? Which is preferable in real time ? These above two concepts came into existence to overcome multiple inheritance un supportive in java
@MrsRaccoon
@MrsRaccoon 5 жыл бұрын
Hi, thank u for your explanation it was very clear, but there's no way i can get why using an abstract method if you have to fill the method in the childclass, isn't the same if i just write the method on every class without making an abstract superclass?? I feel like creating an abstract class makes your code more complicated hahah could please someone explain me
@cphr64x67
@cphr64x67 7 жыл бұрын
why using the abstract methods when u can basically override all ur desirable methods inside the subclasses?
@alisafaei3685
@alisafaei3685 5 жыл бұрын
@@firelordkushroll because you want to be sure when someone is using the abstract class must definitely implements methods that are abstract
@alisafaei3685
@alisafaei3685 4 жыл бұрын
@Wulcrit www.java67.com/2014/06/why-abstract-class-is-important-in-java.html
@traderslearningbackyard2191
@traderslearningbackyard2191 3 жыл бұрын
It is to force subclasses to override abstract method or in another way to assign responsibility of implementing behaviour to child classes
@Master_Trip_BR
@Master_Trip_BR 4 жыл бұрын
Great video, thanks!
@nomik
@nomik 5 жыл бұрын
Awesome explanation!
@ihorsolntsev458
@ihorsolntsev458 7 жыл бұрын
I completely agree with comment below. Thanks for all this video.
@M4RCi92
@M4RCi92 6 жыл бұрын
Clean, concise, informative and good-looking video. Thanks for the help :)
@thebestfella
@thebestfella 4 жыл бұрын
very good
@saiprasadnaik503
@saiprasadnaik503 8 жыл бұрын
sir,,,, can u tell me,,,why we use abstract class,when we have interface??
@deegeu
@deegeu 8 жыл бұрын
The main reason to use an abstract class is when you need to support inheritance. I'd prefer using interfaces when you can. The example is when you're designing a class hierarchy, where you expect the user to derive from your abstract class in order to use it. In this case, there should be shared functionality in the abstract class. If you're simply expecting several classes to share the same similar behavior (method names), then you want to stick with interfaces.
@rajeshdansena
@rajeshdansena 6 жыл бұрын
Check diamond problem in Java also!
@dharmendrasahu6298
@dharmendrasahu6298 6 жыл бұрын
Hi, Could you tell me when to use abstract class and when to use Interface? Thanks, D Sahu
@saratchandra4109
@saratchandra4109 7 жыл бұрын
If an abstract class contains only abstract methods, what is the difference between interface and abstract class with only abstract methods ?
@deegeu
@deegeu 7 жыл бұрын
An abstract class is part of a class heirarchy. Any class extending the abstract class is a child class of the abstract class, and cannot derive from any other abstract class. An interface is just a promise to implement methods in the interface. Any class implementing the interface, can also implement other interfaces.
@saratchandra4109
@saratchandra4109 7 жыл бұрын
Thank you, Deege U for detailed explanation. Is Java a language or platform? What is the definition of platform? Is platform a combination of OS and CPU ?
@tango8011
@tango8011 5 жыл бұрын
@@saratchandra4109 Java is a language and an Object Oriented One.
@fatimauwarilwan4289
@fatimauwarilwan4289 7 жыл бұрын
Can an abstract class inherits another abstract class
@deegeu
@deegeu 7 жыл бұрын
Yes, and it can be abstract as well.
@RicardoJost
@RicardoJost 8 жыл бұрын
Saved me, thank you!
@wesdaaawg
@wesdaaawg 5 жыл бұрын
flawless explanation. thank you!!
@staffordnelson9053
@staffordnelson9053 5 жыл бұрын
good work! Thanx
@vjraggs8315
@vjraggs8315 5 жыл бұрын
Please do a series on java 8+ features like lambdas ..
@voquoc3901
@voquoc3901 4 жыл бұрын
thanks you
@abumusa144
@abumusa144 7 жыл бұрын
The background music is awesome, does anybody know which music it is ?
@zahreddinesoualem3213
@zahreddinesoualem3213 5 жыл бұрын
is "makeDough();" abstract method or not !! !!
@matejpesl1
@matejpesl1 5 жыл бұрын
it is
@justalilbit8887
@justalilbit8887 Жыл бұрын
Btw, abstract class cannot be instantiated if there is any unimplemented abstract methods. But you can still put abstract keyword into a regular class that has no unimplemented methods will be instantiated. So, it's not related with having the keyword ABSTRACT but the Java concept. Just a reminder.
@icloudutech
@icloudutech 5 жыл бұрын
Good
@thesum5919
@thesum5919 5 жыл бұрын
Thanks bro
@andreviniciusbezerradasilv9335
@andreviniciusbezerradasilv9335 2 жыл бұрын
thank u
@anveshsingh8885
@anveshsingh8885 7 жыл бұрын
but why we need it ? if we don't know the the logic then don't declare it but if we know the logic rather define that logic directly in the new class.why this whole process of taking whole lot another class called abstract class Reply
@sidielhaje9698
@sidielhaje9698 7 жыл бұрын
good question !!! , i think that we need it to tell others that they can use an abstract method if they can define its code . e.g: if you create a class that needs 4 methods , and you are able to define the code of just 3 o them ,so you can declare the 4th as an abstract hence if someone else want to use your class and he is able to define its code so he need just to extend your class and define the 4th method .
@vickyanand5898
@vickyanand5898 3 жыл бұрын
Never thought I would get high with bread !
@tenminutetokyo2643
@tenminutetokyo2643 4 жыл бұрын
Forget Java, I want some damn cookies now.
@toughchic6377
@toughchic6377 5 жыл бұрын
Great video though! Thank you!
@rajsankarblogs
@rajsankarblogs 6 жыл бұрын
U have not explane why we go for abstract class? .....u only explsin when we call a class is abstract class
@harishchowdarysure8858
@harishchowdarysure8858 9 жыл бұрын
what is difference betweeen abstract class and interface .................plz reply me
@deegeu
@deegeu 9 жыл бұрын
+harish chowdary sure An abstract class is a partial implementation of a class, while an interface is a contract of methods you declare your class will implement. Interfaces are coming up soon, so I'll cover them in depth.
@harishchowdarysure8858
@harishchowdarysure8858 9 жыл бұрын
+Deege U sir i need real time example.,plz reply me
@saiprasadnaik503
@saiprasadnaik503 8 жыл бұрын
atm machine,,,hides the impl.and show functnlity to user
@napoleonb55
@napoleonb55 7 жыл бұрын
I think the difference is that for a non abstract class, the methods in the super class is fixed in this context, you would implement the same method for baking for all altitudes. However, having an abstract class gives you the flexibility of changing the functions of each method within their own specific context.
@fardeenkhan4662
@fardeenkhan4662 7 жыл бұрын
thank u sir
@LukaszSkyWalker
@LukaszSkyWalker 6 жыл бұрын
Thx!!
@hongcai4617
@hongcai4617 3 жыл бұрын
The example itself doesn't make sense in my real programming..though that bread baking looks so yummy..
@sujit2609
@sujit2609 6 жыл бұрын
Nice background
@bahmanghassemieh866
@bahmanghassemieh866 7 жыл бұрын
Thanks.
@ifstatementifstatement2704
@ifstatementifstatement2704 Жыл бұрын
Whenever you plan to have different implementations of the methods of that abstract class.
@AbhishekKumar-gf2ei
@AbhishekKumar-gf2ei 8 жыл бұрын
what is concreate class?
@deegeu
@deegeu 8 жыл бұрын
It's the opposite of an abstract class. A class that derives and satisfies an abstract class is considered concrete.
@gnaneshwarrao174
@gnaneshwarrao174 7 жыл бұрын
Just a normal class that you create (Which is neither Abstract, nor an Interface). Eg: Class Dog {}
@jaybenton7716
@jaybenton7716 3 жыл бұрын
2:30, I thought I was having a stroke.
@devdylan6152
@devdylan6152 4 жыл бұрын
I want cookies now. :(
@_productivity__nill_1131
@_productivity__nill_1131 4 жыл бұрын
Abstract classes can't be instantiated. A subclass is needed if one wishes to instantiate
@kisshorshrestha9993
@kisshorshrestha9993 3 жыл бұрын
i was confused and came here, i am more confused but with some weird bread recipes now.
@kingburrito7773
@kingburrito7773 7 жыл бұрын
LMAO AT 2:30 REHRETEPIE
@DingleBerrieLol
@DingleBerrieLol 6 жыл бұрын
OMG
@toughchic6377
@toughchic6377 5 жыл бұрын
HAHAHAHAHA! I literally searched these comments to see if anyone else heard it and died laughing!!
@alex123opa
@alex123opa 5 жыл бұрын
thinks changes with java 9 so note that out
@stewiegriffin6503
@stewiegriffin6503 6 жыл бұрын
I get it, but I don't like it. Too complex, too many abstraction. Just make the bread.
@ildaphonse
@ildaphonse 2 жыл бұрын
that bread analogy was not good
@thomasanstey5837
@thomasanstey5837 3 жыл бұрын
I liked the video. Your art most def remind me of this creative painter Oli Mueller! His drawings low-key is similar to Aaron Blaise mixed with Emmy Kalia! He is the most creative painter on KZbin and he goes off on KZbin! Go see his YT out and give Oli Mueller a like! 👉 #OliMueller
Overriding equals and hashCode in Java - 039
6:30
Deege
Рет қаралды 82 М.
Java Interfaces Explained - 040
7:12
Deege
Рет қаралды 155 М.
Help Me Celebrate! 😍🙏
00:35
Alan Chikin Chow
Рет қаралды 85 МЛН
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
SIDELNIKOVVV
Рет қаралды 4,1 МЛН
НИКИТА ПОДСТАВИЛ ДЖОНИ 😡
01:00
HOOOTDOGS
Рет қаралды 1,5 МЛН
My thoughts on framework after daily driving it for 2 years
16:34
Louis Rossmann
Рет қаралды 714 М.
Невероятный разговор о книгах / вДудь
2:50:11
Abstract Classes and Methods in Java Explained in 7 Minutes
7:00
Coding with John
Рет қаралды 527 М.
Naming Things in Code
7:25
CodeAesthetic
Рет қаралды 2,2 МЛН
C# interfaces vs. abstract classes - An EPIC combination?
5:28
tutorialsEU - C#
Рет қаралды 8 М.
Abstract Class In Java Tutorial #79
8:55
Alex Lee
Рет қаралды 544 М.
When to use Abstract class and When to use Interface in Java
20:04
How to write a copy constructor in Java - 037
5:38
Deege
Рет қаралды 35 М.
Abstract Classes vs Interfaces (Java)
9:43
The Code Hard Truth
Рет қаралды 208 М.
Help Me Celebrate! 😍🙏
00:35
Alan Chikin Chow
Рет қаралды 85 МЛН