I have 2 questions 1) why we have to define that method in interface only , we can define method inside implemented class only? like message method with body can be write inside implementation class AndroidPhone, there will be no change in interface then 2) if we want to enhance or add something in default method in implentation class, can we do that? Can we override default method too?
1) See you are modifying your existing functionality right. What if you don't want to break your existing classes while still adding new features(methods) in interfaces. I hope this solves your confusion.
If we are able to define methods in the interface itself then what would be the difference between the abstract class which has concrete implementation and interface where we do have default definition of the method!
avinash kesarla Abstract classes and interfaces have different purposes. With abstract class you have inheritance and the sub class inherits from abstract class (there can only be one abstract super class that the sub class inherits from, you cannot inherit from multiple super classes). Interface provides multiple inheritance. You implement an interface(s), and the only stipulation is that you must implement (and define) the interfaces methods. So think of an interface like a contract that takes hierarchically unrelated classes and creates a relation between them,a super class for unrelated classes. With abstract class there is a logical hierarchy, that's the most important part.
Using List as the reference type helps when you have to change the collection type of the reference for eg. List numList = new ArrayList(); now if you want to use numList as a reference to some LinkedList you can do it directly without creating a new reference because List is the parent interface of both ArrayList and LinkedList. numList = new LinkedList(); So it is a way of generalization and not specialization. Hope this helps.
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 ??? hi bro , 😭😭Naa Friend Okariki OLD UAN number activate kaavatledhu😭😭, Error: 🙏🙏🙏Basic Details like Name, Aadhaar & DOB are mismatched ani Vastundhi🙏🙏🙏 Bro..??? hm alage, within seconds lo (Vs Code) and (Chrome tab) ela change avutunnayi Bro, Please tip cheppu. Two companies(XYZ & IJK) 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?
Can we have more than one default methods in interface? if default method we are defining in the interface it seems like same in the abstract class, what would be the difference between interface and abstract class in java8
I am SO GRATEFUL, thank you very much. Well explained and clarity achieved :)
please make a video on when to use abstract class .when to use interface.
very good
really thanks it helped a lot!!! you are awesome
I have 2 questions
1) why we have to define that method in interface only , we can define method inside implemented class only?
like message method with body can be write inside implementation class AndroidPhone, there will be no change in interface then
2) if we want to enhance or add something in default method in implentation class, can we do that?
Can we override default method too?
1) See you are modifying your existing functionality right. What if you don't want to break your existing classes while still adding new features(methods) in interfaces. I hope this solves your confusion.
2) yes default method can also be overriden.
If we are able to define methods in the interface itself then what would be the difference between the abstract class which has concrete implementation and interface where we do have default definition of the method!
avinash kesarla Abstract classes and interfaces have different purposes. With abstract class you have inheritance and the sub class inherits from abstract class (there can only be one abstract super class that the sub class inherits from, you cannot inherit from multiple super classes). Interface provides multiple inheritance. You implement an interface(s), and the only stipulation is that you must implement (and define) the interfaces methods. So think of an interface like a contract that takes hierarchically unrelated classes and creates a relation between them,a super class for unrelated classes. With abstract class there is a logical hierarchy, that's the most important part.
Why do we do like this :-
List numList = new ArrayList();
and why not
ArrayList numList = new ArrayList();
it's simply matter of choice both will work
Using List as the reference type helps when you have to change the collection type of the reference
for eg.
List numList = new ArrayList();
now if you want to use numList as a reference to some LinkedList you can do it directly without
creating a new reference because List is the parent interface of both ArrayList and LinkedList.
numList = new LinkedList();
So it is a way of generalization and not specialization. Hope this helps.
great like always!
what about static method in Interface? do video for also??
thank you for explaining .
Is default is only keyword ...or it's access modifier is also default ?
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 ???
hi bro , 😭😭Naa Friend Okariki OLD UAN number activate kaavatledhu😭😭, Error: 🙏🙏🙏Basic Details like Name, Aadhaar & DOB are mismatched ani Vastundhi🙏🙏🙏 Bro..???
hm alage, within seconds lo (Vs Code) and (Chrome tab) ela change avutunnayi Bro, Please tip cheppu.
Two companies(XYZ & IJK) 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?
if 2 interfaces have same method names but do different functions and a class implements both the interfaces then which method will it call
class method
Why we are not declared that call method as default that is also by default public/abstract
here default is a keyword or an access specifier ?
yes its a keyword, access modifier of all the type of methods that is abstract, static and default methods is public by default. Hope this helps.
Sir can we use instance variables in default interface.??
No
sir if u override object class methods in interface we will get compile time error ?
Yes
Can we have more than one default methods in interface? if default method we are defining in the interface it seems like same in the abstract class, what would be the difference between interface and abstract class in java8
Why is the ducking screen black
how you comment 4 rows at the same time , and how you uncomment them ?
Use Ctrl + SHIFT + L which will open a list of all major shortcuts for eclipse.