I think the difference in Abstract class and interfaces is that we do not have to extend all the methods in abstract class while all methods will need to be implemented in interface which is not always what we would want to do.
Thank you for your explanations. It's clear my doubt how to implement default method but another doubt was created i.e. what is the use of the default method in Interface? why we use it? where its use in the real world?. Thank you in advance
Sir I want to ask you when we have a default constructor already built within java and when we write our custom constructor which one gets precedence and why
Coding Geeks Think of self created constructor as an "overridden" constructor, which overrides the default one, so you cannot use default one by any means.
you can write default as well as static methods in your interface. Here in your implementation class you can directly use static method with the help of interface name where as you need to use super keyword for the default method. e.g. interface DefaultInterface{ default void method1() { System.out.println("I am Deafult method from DeafultInterface"); }
static void method2() { System.out.println("I am static method from DeafultInterface"); } } public class DefaultInterfaceTest implements DefaultInterface {
public void method1() { System.out.println("I am Deafult method from DefaultInterfaceTest"); } public static void main(String[] args) { new DefaultInterfaceTest().showUses(); } } output: I am static method from DeafultInterface I am Deafult method from DefaultInterfaceTest I am Deafult method from DeafultInterface
One doubt!! Imagine we have two interfaces having same method names and it's implementation? Can a class implement these two interfaces? Which interface implementation will the class be inheriting?
Just tried it and the result is that you have to override the method in this case. Like an abstract method. Checked exception for "unrelated defaults" occurs otherwise.
As a Career GAP Candidate StartUp Companies Lo Job Ela Techukovaalo Cheppandi Sir (or) Mam🙏🙏🙏?? As a Career GAP(6 years) Student How to to get Java Developer Job in this Year 2024??? Hi, I have a 6 years CAREER GAP. how can I get JAVA DEVELOPER Job in 2024 ??? Two companies(ABC & XYZ) lo job vachindhi fake pettanu & alage 1.5 months 2 Companies lo Work Chesanu, Now i am looking for Job, my doubt is Those 2 companies are creating my pf or Not? further in future is it Effect my carrier? hi, How to get job in PayRoll Companies?? and How to Find PayRoll Companies?
abstract class and default method are different ....u can say "why not abstract class instead of Interface" but not "why not abstract class instead of default method" because default method is a part of Interface...but not whole interface.....i hope this makes sense :)
I think the difference in Abstract class and interfaces is that we do not have to extend all the methods in abstract class while all methods will need to be implemented in interface which is not always what we would want to do.
nice info
Your explanations are really great! Thanks a lot for your work.
Thank you for your explanations. It's clear my doubt how to implement default method but another doubt was created i.e. what is the use of the default method in Interface? why we use it? where its use in the real world?.
Thank you in advance
Can you start Tutorial series on how to make extensions for app inventor ?? Please reply !
Wow, I glad I found this channel.
Sir I want to ask you when we have a default constructor already built within java and when we write our custom constructor which one gets precedence and why
Coding Geeks Think of self created constructor as an "overridden" constructor, which overrides the default one, so you cannot use default one by any means.
Can we have only default method in interface without any public abstract method?.If so ,how to call that default method?
Hello sir, as i have tested we can also define methods in interface using static keyword. Can you explain this?
you can write default as well as static methods in your interface. Here in your implementation class you can directly use static method with the help of interface name where as you need to use super keyword for the default method. e.g.
interface DefaultInterface{
default void method1() {
System.out.println("I am Deafult method from DeafultInterface");
}
static void method2() {
System.out.println("I am static method from DeafultInterface");
}
}
public class DefaultInterfaceTest implements DefaultInterface {
void showUses() {
DefaultInterface.method2();
method1();
DefaultInterface.super.method1();
}
public void method1() {
System.out.println("I am Deafult method from DefaultInterfaceTest");
}
public static void main(String[] args) {
new DefaultInterfaceTest().showUses();
}
}
output:
I am static method from DeafultInterface
I am Deafult method from DefaultInterfaceTest
I am Deafult method from DeafultInterface
Sir can't we use lambda expressions for default methods in Interface????? Plz reply 🙏
Sir one suggestion plz provide all these example code in description of your video
Does lambda expression only works with abstract methods of functional interface and not with default methods??
Yes only the one abstract method will work.
One doubt!!
Imagine we have two interfaces having same method names and it's implementation?
Can a class implement these two interfaces?
Which interface implementation will the class be inheriting?
In 1.7, it didn't matter as the implementing Class would overide the method and there was no ambiguity if the method name was same in both interfaces!
Just tried it and the result is that you have to override the method in this case. Like an abstract method. Checked exception for "unrelated defaults" occurs otherwise.
this default method doesn't run in my IDE
excellent video. thank you
REALLY NEW 👍👌👌
As a Career GAP Candidate StartUp Companies Lo Job Ela Techukovaalo Cheppandi Sir (or) Mam🙏🙏🙏??
As a Career GAP(6 years) Student How to to get Java Developer Job in this Year 2024???
Hi, I have a 6 years CAREER GAP. how can I get JAVA DEVELOPER Job in 2024 ???
Two companies(ABC & XYZ) lo job vachindhi fake pettanu & alage 1.5 months 2 Companies lo Work Chesanu, Now i am looking for Job, my doubt is Those 2 companies are creating my pf or Not? further in future is it Effect my carrier?
hi, How to get job in PayRoll Companies?? and How to Find PayRoll Companies?
Thanks a lot bro🎉
Then why can't we use abstract class instead of default ......
abstract class and default method are different ....u can say "why not abstract class instead of Interface" but not "why not abstract class instead of default method" because default method is a part of Interface...but not whole interface.....i hope this makes sense :)
@@srijalkc1975 can we use lambda expressions for default methods in Interface???
could I write more than one default methid in interface?
yes
Yes bro, but only on abstract method!
geiles Video, danke!
Excellent
Thanks😺.
Thank You
Date: 22-11-2024
Day: 04
You never give reply to anyone.That's not Good...