TOP 6 difference between Abstract class and Interface in JAVA || Must know facts
This tutorial covers the difference between abstract class and interface.As we go further with this tutorial we are going to learn the top 6 difference when we compare interface vs abstract class in java.
First Lets talk about what is interface in java and what is the use of interface in java ?
So when we know the specification but not aware of the implementation, then we should go for an interface.
Then the next question will be what is abstract class in java and what is the use of abstract class in java ?
The answer is very simple, When we know the partial implementation then we should prefer abstract class.
I will try to demonstrate you the difference between interface and abstract class with a simple example with this tutorial.
——————
The abstract keyword is used to create an abstract class whereas interface keyword is used to create an interface.
——————
The variable of an abstract class can have final, non-final, static and non-static variables whereas the variable of an interface should be always public static final.
————————
Another difference between abstract class and interface in java is :
we can achieve multiple inheritances by using interface whereas with an abstract class it is not possible as multiple inheritance is not supported by java.
——————————
An interface can’t have a constructor within it whereas the abstract class can have a constructor within it.know all the reasons why the abstract class does contain a constructor, you can follow the below tutorial by clicking on the link :
[
Why we need constructor inside an abstract class ? || Popular Java interview question
———————————
An interface in java can have an only abstract method within it whereas the abstract class in java can have both abstract and concrete method within it.
(FYI: from java 8 we can have both concert and abstract method within an interface )
To know more, watch this tutorial :
INTERFACE IN JAVA 8 with REAL TIME code ||Why DEFAULT Method?[Explained]
——————————————
Well, we can have few more differences as well but these are the few common difference between abstract class and interface in java that each developer should
aware of.
——-
Please subscribe to my channel by clicking on the link below.
Stay tuned and like my Facebook page for more.
Music :
———–
credits : –
Adventures by A Himitsu
Creative Commons — Attribution 3.0 Unported— CC BY 3.0
Music released by Argofox
Music provided by Audio Library
—–
intro template :
wwww.youtube.com/Alexbau01
Tag: abstract class vs interface java, slenium express, difference between abstract class and interface, what is interface in java, interface vs abstract class in java, what is abstract class in java, when to use abstract class and interface in java, interface and abstract class in java, abstract class vs interface java, what is the use of abstract class in java, difference between interface and abstract class in java, difference between abstract class and interface in java, interface in java, abstract class in java
Xem thêm bài viết eSports: https://aomalley.org/esports
Nguồn: https://aomalley.org/
Nice bro. thumbs up (go to 5:55 and make some correction you made both abstract method.)
Very clear explanation
Interface used for two purposes in real-time projects
1)to achieve multiple inheritance (1:M)
2)to hide internal implementation
And interface means you are providing user to access these methods only from implemented methods ,user cannot access non overriden method try it yourself
Interface is like from one stone two birds are fallen.😅
greeat video man, after many tries to understand, this served me the best.
Only theory give real time explanation
nice tutorial, loved it
Prashant from Sairat movie?? JK haha, nice explanation though, thanks!
Absolute legend, thank you for the wonderful lession!
Awesome Bro, thanks a lot!
bakwaas bilkul…not useful.
wow <3 thx for this
Sweet
Thanks for sharing
Hi Abhilash, thank you for such a clear explanation, I think at 16:47 you meant B(int i){ this.i = i} while creating a constructor in the abstract class B, but you have typed A(int i) instead of B.
better bro
I didn't know we could declare methods with a body in an interface or variables in an interface. I have no idea about Java but in Csharp that is not allowed. In C# you only declare abstract methods, i.e method without a body. So, the only benefit is that interfaces allow multi-inheritance, which is good, while abstracts don't. But abstract classes can contain properties, non abstract methods as well as abstract methods. Is that right? Good video, thanks a lot.
paint your wall, your board is crooked, great video, ty
One question, what is the use of constructor in abstract class when we can not instantiate it?
thanks…you are so cool.very clear explanation
Good explanation
One more difference is we can declare main method inside the abstract class..But in interface we cannot
Java 1.8 having default method, I have doubt still we do need abstract classes?
Superb explanation… Thank you
Object of interface and abstract class can be created by the jvm but not by the programmer.
nice man.. thanks for your time explaining others
Still I am not clear.. after java8 introduces interface with default methods… I don't see any strong reason why do we need 2 go for abstract class… Could u pls tell me
Great explanation…i searched lot of material for findings the difference but you have given best explanation at very point to point info….well done!!!
We can create object in abstract class bro…and when we create object of it costructor of abstract class gets called😎✌🏼
thank you.You got a new subscriber😇
Great 👍
Why use an interface when the class can directly implement the functions?
then what is the use of abstract class now
Best Instructor at Best time . Currently I am trying to switch company your videos conatins most of those questions with best answers(Indian Version). Feels like entire Java interview questions at one place .
Thanks is a small thing 😀
Nice,superb…………………………………………………………………………………………………………………………………
abstract class test1 {
void print ()
{
System.out.println("hello abstract !!");
}
}
public class test extends test1 {
void print ()
{
System.out.println("hello world !!");
}
public static void main(String[] args) {
test t = new test();
t.print();
}
}
Here how to print "hello abstract !!" ?