This is wat I m expecting ..from last 4 year I was not getting it ..everyone is just explaining theory part..you are explaining with practical examples ❤ loved it bro
Video is nice, but dear sir at some points your tongue is sliping for wrong words. This is the best vdo about interface and abstraction, gone through many.
0:29 abstract class 1:34 partial abstraction and code reusability 3:05 bank example 7:43 no instantiation 8:33 interface 12:55 abstraction 14:07 difference: abstract class extensibility vs interface multi-inheritance
Good Explanation , small note: in java 8 interface can have a default implantation , so you don't have to implement in sub classes if you provide the default behavior in the interface
Good explanation but only one correction. Abstraction class can contain all the non abstract methods as well. It is not required to have abstract class atleast one abstract method for being it an abstract class. The main motive of abstract class is that it can't be instantiated.
An abstract class is a class that is declared abstract-it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
Why would he hate ? he might be a Hindu and an Indian that doesn't mean he hates Muslim, We Indians may hate Pakistanis for creating issues in the countries ... Even we have a lot of Muslims in India and we treat them as our brothers and sisters ...HA HA I guess that's a lot of information Don't mind me ....I was Just saying...
@@RajuAhmed111 same we can also achieve using abstract class by defining abstract methods only.except multiple inheritance support what is the other advantage of interface.
Hi Siva, Thanks a lot. I was too confused about the abstract and interface, where to use what. This question was repeatedly asked by interviewer, and as result i was not able to answer appropriate logic behind each one. Regards, Mohit
Hi siva sir 1)Plz explain the difference b/w abstract class vs interface of java 8 2)Difference b/w inteface of java 7 or below versions of java and intefaceas of java 8 interface?
Hi sir Why do we use an interface and not an abstract class? What if I implement the same method in an interface and abstract then? Any difference? recent interview question asked
@@SivaReddyJavaTechie Hi Sir, I have one question, is this possible to control a class to access only required methods of an Interface A, A is having test1 and test2 methods, Class B implements A, now I want B can access only test2. Is it possible? (in java 1.7 or 1.8)
There is no need to have atleast one abstract method in an abstract class. But if one of the methods are abstract then the class must be an abstract class. Please confuse the viewers with wrong definitions.
abstract class conatin all the methods as concrete also, there is no rule like you need to mention atleast 1 abstract method as you mention @Siva Reddy
Hi Siva Reddy , Good explanation .... I have one doubt , at last in that AbstractClassDemo.java program had one error i couldn't find that error please explain me . because i'm not that much familiar in java . error : 20th line "Private int amount = 0;"
Siva - This is called as runtime polymarphism where you have same method signature in both super class and sub class but at runtime sub class method overrides the super class method.
It would also be nice to give us examples in day to day coding life... eg. like... OnClickListeners are an Interface. What about an example like that with Abstract class.
I thought you will give us insight when to use what? It's certainly not the case that if my all method is abstract, I should be switching to interface. Interface and abstract class have much more difference and power in term of when to use and how. If all methods need implementation, I can create abstract class with all abstract method. Then why Interface is required at all.
If you do like this, you have only one e sub class .. If you go for interface you can implement multiple sub class , and java don't support multiple inheritance...so we are going to. Interfaces
I've seen people using both of them together but din't get this why .i.e subclass inherit abstract class and implements an interface as well . If we can create mandatory methods in abstract class already then why using interface for creating mandatory methods for subclasses? Like we created calculateInterest in abstract class so that it should be mandatory for all subclasses then why we used interface to create other methods , They can be created as abstract methods in abstract classes ? So what is the actual purpose of using them together ?
Use Interface - When all the subclasses want to implement their own implementation for all the methods defined in Interface. Use Abstract class - When there is common methods that can be extends to as it is. This will help code reusable and if any sub class want its own implementation then , sub class can override those methods
u explained both concepts with sane example.but i didnt understand when to choose interface and when to choose abstract. can u pls give some real time scenarios
Interface provides 100% abstraction in Java. Interface is used to provide as a contract for the implementations. In a system it is possible to have the multiple class having the same method name but implementation might be changed from one sub class to another sub class when you providing the functionality for the methods. Hence using the interface, you provide as a contract for the business. E.g: in the case of JDBC, java provides Statement as interface and it have below methods. 1) public ResultSet executeQuery(String sql) 2) public int executeUpdate(String sql) 3) public boolean execute(String sql) 4) public int[] executeBatch() For Java, it does not matter for which database it has to execute the queries as long as database vendor provides the functionality for the above methods. Also each database(oracle, DB2, mysql) can have their own implementation for executing the queries. Abstract class : Go for abstract class when all sub classes methods having the same functionality of the super class method then it is better you can provides those common methods in the abstract class and which you feel implementation is differ in sub classes declare them as abstract methods so that sub classes can only provide implementation for the abstract methods and other methods can be used as code resuable
If you bring code and implementation logic the actual meaning is lost.. Firstly Abstraction and Interface one needs to look at the actual meaning of the words.
Yes, and you cannot instantiate it either, of course. If you extend a class with an abstract class and not define or provide the implementation for the base class abstract methods then the child class extending it would automatically become abstract.
you said no need to implement concrete method in while inheriting abstract class then y do u override getadrress method ....then overided method is executed in the output ???aaa chepandi
Here is the scenario : If you don't want super class implementation getaddress method in sub class, you can override and get what ever the functionality you want in the subclass method getaddress method. this is based on the requirement, as long as you are happy with the concrete method implementation in super class can be used as it is then no need to override else you have to override it. Hope it is clear now.
You said "Abstract class is a class which contains atleast 1 abstract method"...HttpServlet is an abstract class , but it doesnot contain any abstract methods....Apart from this point,NICE EXPLAINATION :) Keep helping
Suman - Abstract class is a class which contains at-least one abstract method or if we have any requirement where only sub class need to create object for the super class then you can declare class as abstract so that nowhere possible to create object for abstract class expect using the sub class which extends that abstract class. Thanks for liking the video.
Then Siva why didnt you mentioned that in the video, that means you are sharing half knowledge and some one might get rejected for answering this way in the interview. Please be careful about such things in the future.
Yeah, it think what you are trying to say is that an abstract class may or may not have an abstract method, we don't need to have an abstract method in the abstract class, and it sounds weird as there's no point in that, however, if we mark any method as abstract then we must mark the class as abstract too. @SivaReddy, Nice explanation! The video is really helpful.
Suman Ghimire Abstract class may contain or may not contain abstract method abstract class Test { It will wotk; } Class Test1 { abstract void check();//it will generate error }