ABSTRACT METHODS AND ABSTRACT CLASS - JAVA PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in the previous session we have seen the differences between method overloading and method overriding concept so in this session we will see what is meant by an abstract class and abstract methods let's try gas and methods first the abstract matter what is my balance tank method if any class consists of only the declaration of a method is there and hiding the implementation part that was a definition part then we call it as an abstract method the pins only declaration but no definition such methods we call them as abstract methods which will then accept cash we know that any gas may contains the instance variables as well as the methods and constructors right so if any class consists of at least one abstract method then the cash will be calling as abstract class Paris contains at least one as abstract method is called an abstract class so here an abstract class may consist of both the abstract methods as well as them may have normal methods so abstract tests can help abstract methods on normal methods right next then we have to write the implementation of these abstract methods the things here we are saying the glass will contain only the declaration part it will hide the implementation part so here the question is where we how to write the implementation part so that must be written in a derived class right so this will be the painting class and the implementation part will be written in the dinner glass so that means we have to use the inheritance concept here so implementation of abstract methods will be written in derived class right and there is a one more terminology we have to know that is concrete class what is meant by concrete class so the gas contains the complete implementation of all the methods that class we call it as a concrete class complete definition for all the methods it should contain the complete defection for all the methods which are written in the gaps that has been quality the concrete yes right so Aztec method as I can sir a confidence one more thing we have to remember if it is an abstract class object cannot be created right so object cannot be created or instantiate it for the abstract class if it is a concrete class object can be instantiated that was created so we know how to create an object right so if it is an abstract class the object we cannot create an object because we cannot instantiate an object right so whatever the method we are writing we have to use abstract key word abstract keyword and if it is an abstract class here also we can we have to lose abstract keyword for this gasps hope you understood so let us write the program simple program example so that your doubts will be clarified hope you notice of these things abstract method as a class and the concrete class C that is right here so they are writing Class A in the class EA I am just writing the dick affirmative so so why some display this is for a declaration so let me explain the put the declaration a definition right now right so if you if anyone is having the doubt that they've what I said the friends between the declaration of a method and the definition of the method just sit here so this is called declaration and this is called definition right so complete definition this is called a defection this is called a declaration so here if fast acceleration is there but there is no implementation that we call it as a abstract method so see here we here we are writing more a declaration so this is an abstract method and every abstract method should be declared by using abstract table so here we have to write here and sprat have stack void display and if any class consists of these abstract methods that can mean the class itself is an abstract class and it should be declared by using abstract so here also we have to write an abstract before the kasi right so this is the effect class yay now I'm right here Class B extends P right in here that's concept now device implementation back here wide display system dot out dot println you can break glass right so this is called abstract class before mr. abstract class this one is their abstract method and here in this caste Billy we are writing the implementation this is called concrete class because here we are writing only one method that is also completed by uniting the definition so we cannot create an object for class here but we can create an object for cash be so you have to access the methods of at a scale we have writing the inheritance concept now let us write here - abstract public static void main some string are tournaments here we cannot create an object for class here because it is an abstract class we have to create an object for Class B so the object is equal to MU a constructor so by using the object will have to all the display method Hey so hope you understood this one what an abstract class concrete class in this class we are implementing the effect method so this is the derived class for the class here right so here the output will be classy now if this gas is also having one more abstract method so again I am writing one more abstract method and strength void so so I have I have said that a caste may contains the abstract methods as yes hello tormentors so here they ask me consists of normal method as well as more extract method so if any caste and system it is one abstract method that will be calling as an abstinence will your class be is also an abstract class so you have to replace the statement and strength Class B extends a now then we have to write this implementation again we have to write one more class which extends Class B right because the implementation part of this extract method should be written in their areas so here I'm writing can see extends Class B here we can find why show system dot out dot println Class B right so here both are the abstract classes can see will be the complete class because Class C doesn't contain any abstract class in effect methods so a class which doesn't contain any abstract methods that we call it as an app companies so that's why this is a concrete class and we cannot create an object for Kassia or class P because both are the abstract classes so this statement is wrong see right now we're creating an object for see see the webcast of casts B so C object of C can access both the metals of Class C and Class B and again Class B is again there are pairs of Class A so object can the same object can access the methods of class here here there is no method cell class here because only the abstract method is there there is no implementation part of the method right so this the output is so here we can call the same thing object dot so so the output will be Cassie and Gatsby right so hope you understood this one so once again I am repeating so whatever the method we are waiting only the deterioration but not the definition that method we call it as an abstract method and every abstract method should be declared by using the keyword abstract and if any class consists of at least one abstract method that is called as abstract test and if any class which consists of which doesn't consists of abstract methods that is called a concrete class and we cannot create an object for abstract classes we can create the object for only the concrete classes and we have to write the implementation part of the abstract method in the derived class that means we have to apply the inheritance concept here right so hope you understood this one if you are having any doubts regarding these abstract methods feel free to post your thoughts in the comment section now let us see the implementation part of these abstract castes and abstract methods in the compiler hello friends we will see the implementation of these abstract methods and the classes so as we have said that abstract method means there will be only the declaration part but there will be no implementation part so that means hiding the implementation details those we will call it as abstract methods and whatever the class is having these abstract methods those classes we call it as abstract classes now let us create a class class a here just I will write one declaration just a declaration but not a definition right so this is an abstract such classes we have to declare with a abstract so here this method is a abstract method so this class will be an abstract so we have to declare this class also with the abstract abstract class if it is an abstract class we cannot create an object for the def struct class so object cannot be instantiated right so we will create a one more class B which extends a so in the derived class we can write the implementation part of the abstract I mean we can write the implementation part of the abstract method which is written in the abstract class so in the class J we are writing one abstract method that definition can be written in Class B now I will write the definition display abstract method in a right now I will write a main method abstract main right so here we cannot create an object for class here because it is an abstract class we can create an object for class P so be obj is equal to mu B so I have created an object and now I will call the method of an abstract class right display so here the implementation part we are writing in Class B so let us see this abstract main dot Java let us execute this one so it is excessively compiled now let us execute this one abstract main so it is displaying the text abstract method in a see if you are creating an object for Class A you will get an error because we cannot create an object for class yet see error a is a abstract cannot be instantiated so for any abstract class we cannot create the object okay so here as we have said that abstract class may contain the abstract methods or a normal methods now let us see so in a Class A we are declaring it as an abstract and in that we are writing one abstract method now I will write a one actual method right have written one method definition and one abstract method in class yet so even though it is having one method definition if it consists of any one abstract method that class will be considered as an abstract class so if it is an abstract class an object cannot be created for that particular abstract X right so now so here we are creating an object for being and we are accessing obj tour display and again we can access obj dot Show which is written in class a because we are writing the inheritance concept so B is the derived class and ya is a base class so we can acquire the properties of class yang so that the beacon access the methods which are written in Class E that is executed si yes successful compilation abstract method in a and a show method right hope you understood this one so an abstract class can may contain the abstract methods and a normal methods both and the abstract method implementation should be written in the child class that means a derived class right so that means overridden no if we write this one in Class B we can write there so we can we can write in normal methods and the implementation of the diopside-- methods in the class there are class right so here also we can get the same output see here also we are getting the same output right so here with the class which consists of all the method definitions completely is called a contra class so that means a concrete class you should not contain any abstract methods and an abstract class must consists of at least one abstract method and we cannot create an object for the abstract class we can create an object for object for only the concrete classes see if if as we have said that a class an abstract class can contain the abstract methods and a normal methods see in this example I am writing the implementation part of the abstract method and again I am creating one hour another abstract method abstract void show this is an abstract method returning derived class right hope you understood abstract class ei consists of one abstract method class B extends class here so class in the Class B we are writing the implementation of the abstract method which is declared in Class A and again we are writing one abstract method in Class B so here the class consists of one abstract method so this will be also an abstract class it's not a normal class concrete class it's an abstract class again again we have to write the implementation from the derived class right so again right on C extends B so that means just this type of implementation we have seen in multi-level inheritance right so AB a Class A Class B extends here Class C extends be here Class C is the concrete class because here we are writing the implementation part of the abstract method which is written in Class B println flow method in see right now if you execute this one again we will get an error because here we are creating an object for Class B which is an abstract class so for abstract yet we cannot create an object so here we have to create an object for concrete class that is C C now if you execute this one so successful compilation the same thing we will gather right so hope you understood this one so here I am writing one abstract class in the abstract class I am writing only one abstract method in the second class that means a derived class again I am writing one another abstract method so the derivative straight class and again from that again I am writing another derived class which can in which we are implementing the abstract method which is written in derived class B so that particular class we call it as in concrete class right so here we have to remember a few things once again I am repeating so if any class consists of an abstract methods then it should be called as an abstract class and if if it is an abstract class we cannot create an object for that abstract class and an abstract class may consists of both the method definitions as well as the abstract methods normal methods and as well as the abstract methods write an abstract method is giving only the declaration but hiding the implementation that is called abstract method so all this we have to remember while implementing this abstract class and effect methods hope you understood this concept right so if you are having any doubts regarding these abstract class and abstract methods feel free to post your doubts in the comment section so that I will definitely try to clarify all your down and if you really understood my sessions like my sessions share my sessions with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 103,234
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, java programming, java basics, java fundamentals, beginners, programming fundamentals, java faq, java introduction, object oriented, oops, oop concepts, abstraction, inheritance, polymorphism, encapsulation, class, object, multithreading, method overloading, method overriding, single inheritance, extends keyword, hierarchy, child class, sub class, derived class, parent class, super class, base class, abstract method, abstract class, concrete class
Id: p_4Dyfplqkw
Channel Id: undefined
Length: 26min 44sec (1604 seconds)
Published: Tue Feb 19 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.