Тёмный

When to use an abstract class in Java - 038 

Deege
Подписаться 26 тыс.
Просмотров 125 тыс.
50% 1

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/

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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
@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!
@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.
@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. 😊
@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 !
@palkia1416
@palkia1416 7 лет назад
nice explanation, also the song is great
@bengrzybowski7671
@bengrzybowski7671 2 года назад
Very concise. thank you.
@shaun1114
@shaun1114 3 года назад
THIS WAS AN AMAZING EXPLANATION. Thanks
@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?
@Ali-mi9up
@Ali-mi9up 5 лет назад
What an absolutely awesome tutorial. Deege U does it again!
@ciaranmckenna5034
@ciaranmckenna5034 7 лет назад
Including some live code would really improve this video, thanks for sharing though.
@lucasmelo010
@lucasmelo010 6 лет назад
Very well explained in less than 5 minutes. Thanks!
@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.
@Master_Trip_BR
@Master_Trip_BR 4 года назад
Great video, thanks!
@ihorsolntsev458
@ihorsolntsev458 7 лет назад
I completely agree with comment below. Thanks for all this video.
@michaelsteinberg3272
@michaelsteinberg3272 6 лет назад
Finally an explanation that made sense 👍
@nomik
@nomik 5 лет назад
Awesome explanation!
@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.
@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!
@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
@thebestfella
@thebestfella 4 года назад
very good
@RicardoJost
@RicardoJost 8 лет назад
Saved me, thank you!
@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?
@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
@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"
@wesdaaawg
@wesdaaawg 5 лет назад
flawless explanation. thank you!!
@voquoc3901
@voquoc3901 4 года назад
thanks you
@M4RCi92
@M4RCi92 6 лет назад
Clean, concise, informative and good-looking video. Thanks for the help :)
@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
@lil_jeke
@lil_jeke 2 года назад
But you didn’t answer when to use abstract classes and when not to use them?
@abumusa144
@abumusa144 7 лет назад
The background music is awesome, does anybody know which music it is ?
@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!
@staffordnelson9053
@staffordnelson9053 5 лет назад
good work! Thanx
@tenminutetokyo2643
@tenminutetokyo2643 4 года назад
Forget Java, I want some damn cookies now.
@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.
@fatimauwarilwan4289
@fatimauwarilwan4289 7 лет назад
Can an abstract class inherits another abstract class
@deegeu
@deegeu 7 лет назад
Yes, and it can be abstract as well.
@icloudutech
@icloudutech 5 лет назад
Good
@vjraggs8315
@vjraggs8315 5 лет назад
Please do a series on java 8+ features like lambdas ..
@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.
@andreviniciusbezerradasilv9335
@andreviniciusbezerradasilv9335 2 года назад
thank u
@ifstatementifstatement2704
@ifstatementifstatement2704 Год назад
Whenever you plan to have different implementations of the methods of that abstract class.
@thesum5919
@thesum5919 5 лет назад
Thanks bro
@dharmendrasahu6298
@dharmendrasahu6298 6 лет назад
Hi, Could you tell me when to use abstract class and when to use Interface? Thanks, D Sahu
@toughchic6377
@toughchic6377 5 лет назад
Great video though! Thank you!
@vickyanand5898
@vickyanand5898 3 года назад
Never thought I would get high with bread !
@jaybenton7716
@jaybenton7716 3 года назад
2:30, I thought I was having a stroke.
@zahreddinesoualem3213
@zahreddinesoualem3213 5 лет назад
is "makeDough();" abstract method or not !! !!
@matejpesl1
@matejpesl1 5 лет назад
it is
@LukaszSkyWalker
@LukaszSkyWalker 6 лет назад
Thx!!
@fardeenkhan4662
@fardeenkhan4662 7 лет назад
thank u sir
@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.
@sujit2609
@sujit2609 6 лет назад
Nice background
@hongcai4617
@hongcai4617 3 года назад
The example itself doesn't make sense in my real programming..though that bread baking looks so yummy..
@bahmanghassemieh866
@bahmanghassemieh866 7 лет назад
Thanks.
@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 .
@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 {}
@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
@rajsankar8185
@rajsankar8185 6 лет назад
U have not explane why we go for abstract class? .....u only explsin when we call a class is abstract class
@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
@ildaphonse
@ildaphonse 2 года назад
that bread analogy was not good
@stewiegriffin6503
@stewiegriffin6503 6 лет назад
I get it, but I don't like it. Too complex, too many abstraction. Just make the bread.
@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 RU-vid and he goes off on RU-vid! Go see his YT out and give Oli Mueller a like! 👉 #OliMueller
Далее
Overriding equals and hashCode in Java - 039
6:30
Просмотров 82 тыс.
Which part do you like?😂😂😂New Meme Remix
00:28
Abstract Class In Java Tutorial #79
8:55
Просмотров 543 тыс.
Abstract Classes and Interfaces
26:34
Просмотров 304 тыс.
Java Interfaces Explained - 040
7:12
Просмотров 155 тыс.
Lambda Expressions in Java - Full Simple Tutorial
13:05
Abstract Classes vs Interfaces (Java)
9:43
Просмотров 208 тыс.
If __name__ == "__main__" for Python Developers
8:47
Просмотров 407 тыс.
Java encapsulation 💊
8:27
Просмотров 116 тыс.
Map and HashMap in Java - Full Tutorial
10:10
Просмотров 583 тыс.