I have an idea for that, we just change type data, for example, we declare that A obj = new B(), and we could you some methods that belong to the A class. But we want to use the run function that belongs to the B class, simply using this command ((B) obj).run(). It will work well.
Also there are new features for interfaces in new JDK version, where we can use default method and static method with implementations inside a interface class. FYI
I asked myself the question and tried it out since I was not sure what would happen. All of a sudden I love interfaces lol. You can restrict by making the object of either type 1 or 2 (interface 1 or 2) or you can make it access all interfaces by instantiating an object with the type of the implementing class so it gets access to both interfaces since the class implements both. even works if the interfaces methods have the same name, since they have no body you have to implement the method body once yourself. cool stuff!
@@TuxTuxedo-oc9kgomg I just realized by reading your comment that I can access the methods in both interface A and X by creating an object of class B with class B as the reference. different approach than what sir navin did in this video.
The B class should be abstract when we not define all abstract methods in it and later we can define remaining methods in sub class of B. Then finally the subclass of B should be non abstract class.
I started with Navin 3 years ago. I've watched lots of others since aswell but he remains the best.
sir u r perfect always do crisp video upto point. Thank u so much for such amazing playlist.
I have an idea for that, we just change type data, for example, we declare that A obj = new B(), and we could you some methods that belong to the A class. But we want to use the run function that belongs to the B class, simply using this command ((B) obj).run(). It will work well.
Yes it worked, but don't you think it is written purposely . Like behind it we have a reason?
This is call method casting for obj reference. Am i correct?
is this a one-time use(liek after that command the reference is still A)? or does is change the reference of the obj from A to B?
Also there are new features for interfaces in new JDK version, where we can use default method and static method with implementations inside a interface class. FYI
great explanation. thank you so much 🤩🤩
You missed why we use the default private and static method in interface after Java 8 ?
I also observed you can extend a normal class and implement an interface within one class
If you could explain method chaining and calling these methods, that would be great.
You're saving my life! Thank you!
you're saving my money
Better to create class B object with reference B so that we can access all methods of interfaces and class B
I asked myself the question and tried it out since I was not sure what would happen.
All of a sudden I love interfaces lol. You can restrict by making the object of either type 1 or 2 (interface 1 or 2) or you can make it access all interfaces by instantiating an object with the type of the implementing class so it gets access to both interfaces since the class implements both.
even works if the interfaces methods have the same name, since they have no body you have to implement the method body once yourself.
cool stuff!
@@TuxTuxedo-oc9kgomg I just realized by reading your comment that I can access the methods in both interface A and X by creating an object of class B with class B as the reference. different approach than what sir navin did in this video.
Sir even class b also should become abstract because the methods we using are abstract in interface class
The B class should be abstract when we not define all abstract methods in it and later we can define remaining methods in sub class of B.
Then finally the subclass of B should be non abstract class.
Ok cool but I don't understand what the "need" for interfaces is here, since you only show that we can use interfaces as well as parent classes.
If all methods are abstract, we can go with interface,
But if it is partial like any of the method is concrete then we can go with abstract class
(Next Video) Need of Interface in Java -> th-cam.com/video/AG_7wWFBquQ/w-d-xo.htmlsi=Pb8fNRY3lLjxzrL7
Sry mapla I'll not interested😜