Abstract Class in Java: Top 10 facts that you should know About it and it's used in Software Engineering Design Patterns and OOP (Object Oriented Programming) everywhere. There are top 10 facts that you should know about Abstract Class in Java. Even though it is in Java, but you can apply these things to other OOP languages.
If you new, my channel is about Android App Development Tutorials and Java Programming. And I just create a new course series called Design Patterns of Software Engineering. And Abstract class will be used a lot in the course. That is why before you can begin, you have to understand the abstract class.
Abstract class is one of the most useful features in OOP, yet Abstract class in Java is a difficult subject to understand for most OOP beginners. Abstract class is a bit mysterious its own way. It has been employed every time in Design Patterns. The first reason to use Abstract class is polymorphism. I will make another video to explain why you should use Abstract class, and why you use polymorphism and how to do it.
Number 10, Abstract class in Java must declare with "abstract" modifier.
Unlike a usual class, or a concrete class that you begin it with class keyword with one of 4 modifiers (public, protected, private, or blank for default), abstract class must declare with abstract modifier. Even though it is obvious for learners, but it is also important to stress out first.
Number 9, Abstract class in Java Cannot Create Instance.
One of most iritated thing about abstract class which seems also like to break the OOP rule that you can create an instace from a class. In fact, abstract class is a way to prevent you from creating the instance. There is a good reason why and when you don't want to let anyone to create an object from a class. We will learn more about it.
Number 8, Abstract class can be called by inheritance.
Even though you cannot create an instance from an abstract class, it does not mean it is the end of it. You still can get any non-private methods and properties from your parent class by inheritance.
Number 7. Abstract class Can be a type class.
Remember that I told you about polymorphism? How polymorphism works then? I will dedicate a video about polymorphism in Java but now I can tell you this: polymorphism will let declare an instance to be of a parent class type and then you can point to the child class. So Abstract class will always be your parent class type. Imagine a strategy game that in your game you can create many soldiers. But there are 3 types of soldiers like Marine, Airbone and Commado. They have common skills but different type of soldiers have different type of skills too. It is a good idea to create the Soldier class as the Abstract parent class and the others are the concret child classes. Now you can declare an instance named John Wage, for example, with a Soldier class type but he is a Marine.
Number 6, Abstract class in Java can have both abstract methods and concretes methods.
As in our earlier example about the Soldier, some skills are common like shooting, jumping, walking, but the other skills like parashooting is just for the Airborne soldiers only. That is why Abstract class can have both concrete methods for common skills and abstract methods for special skills.
Number 5, Abstract methods Without Body Code.
Why abstract methods have no body code? This is the most common questions students have ever asked. And followed by another question like, if there is no code, how does it work without no code? Well, the answer is, it does not work without code. But the intention of Abstract class is not direct call from users. You see, people always confused that after they create a class, they can just use the class. But there can have another layer below the class. In the case of Abstract class, it is the first layer, and its subclasses which are the concrete classes are the second layer, and finally, the user class is in the third layer. So in the 2nd layer, the subclasses must implement the abstract method. It means that you will fill the blank.
Number 4, Abstract method must be implemented.
Number 3, Abstract class Can Have Constructor.
Number 2, Abstract class Cannot Be Final.
Number 1. Abstract class Is Not Mandatory.
Here are the top 10 facts that you should know about Abstract class in Java.
Please visit my website to get the latest tutorial and source code:
http://kosalgeek.com
Thank you very much,
Oum Saokosal
The Creator of Channel Oum Saokosal and Kosal Khmer Tech
Credit Music:
"Tabuk" Kevin MacLeod (incompetech.com)
Licensed under Creative Commons: By Attribution 3.0 License
http://creativecommons.org/licenses/b...