Transcript for:
Understanding OOP Concepts in Java

hello everyone this is lakshman welcome back to our youtube channel in the today session we are going to talk about oops concepts in java programming language with real time examples as we all know object oriented programming concepts are very important nowadays so irrespective of programming language you must understand in-depth knowledge on oops concepts so ops is nothing but object oriented programming so whether you are learning java programming language python programming language.net or php any one programming language but the oops concepts are mandatory so without having an idea about oops concept you will not able to design the systems in object oriented programming model so it simplifies the software development and maintenance using oops concept we can develop the fcn and reliable applications java oops concepts provide several advantages such as security reusability effective communication developing complex software maintenance and fcnc now we will talk about what are the major object oriented programming principles so there are four major object-oriented principles are there the first one is abstraction encapsulation inheritance and fall margin so i will explain it an easy way by taking a real-time examples okay first let us talk about abstraction so abstraction is one of the fundamental object oriented programming principle abstraction is a technique which is hide the unnecessary data from the user and it only expose the necessary data for the user then how can we achieve abstraction in java so there are two ways are there to achieve abstraction those are nothing but by using abstract class and interfaces by using abstract class and interface we can achieve abstraction java so let me take one real-time example then you can understand how the abstraction works in java okay so suppose i am taking example atm mission i hope everyone visit the 8th mission so on the atm screen you can see different options available like check balance withdraw transfer money pin change okay etc you can see options like that on the atm screen the user wants operate on these uh options only whenever user wants to check his balance he will choose the check balance option but he doesn't want to know how the internal processing happening when so whenever user check the check balance option okay so that is nothing but abstraction so what abstraction does it shows only necessary data to the user these are the necessary data to the user to operate the atm mission okay but unnecessary data means these implementation part what happening internally the user don't want to know that thing the implementation part internal thing internal processing he doesn't want that is nothing but abstraction okay so we can achieve abstraction by using abstract class and interface so let me take one example like a class atm so in the atm class we have declared methods with transfer money check balance these methods are incompleted that means without body so whenever you are declaring without body that method should be declared a keyword abstract abstract keyword so if any class contains abstract method that that class should be declared abstract class using by using abstract keyword abstract class it contains abstract method as well as concrete method concrete method means implemented methods okay at the same time without body methods that means incomplete methods also available then what about object creation for abstract classes we cannot create the object because in the abstract class we have incomplete methods suppose if you are creating object for atm [Music] by using this class object reference we are calling these methods like atm atm equal to new atm like atm dot withdraw so if you call by using this reference in particular method then what will happen there is no implementation in this class okay so that is the reason we are not going to create the object for abstract class so by using abstract class it will only display the necessary details like check balance withdraw transfer money like this but implementation part here we are implementing the developer is responsibility to implement these abstract methods by using another class by creating another class okay here we are implementing those methods like public wide withdraw we are implementing that code here okay and one more real-time example is sending sms through mobile [Music] like we are just typing the message and just click on the send button we don't want any the internal process how the message will reach to the customer but the user expecting only the required data you don't want to unnecessary data like how the internal processing happening i hope you understand what is abstraction in java first one is encapsulation in java encapsulation means it's the process of binding the data and corresponding methods in a single unit that is nothing but encapsulation a java class is nothing but an encapsulation because in in a class the data members and corresponding methods are binding together so let me take one example here so in a test class data members and corresponding methods are binding together this is nothing but a encapsulation then how we can achieve encapsulation in java so if you are declaring any variable with a private keyword then those variables cannot accessible from outside of the class that means we are etching the security that is nothing but encapsulation so during the development of banking software so if you declare the variable balance variable as public then anyone can access your balance so do you want such type of software no okay only the authorized person who have user id and permission details those candidates though that guy only can accessible to see the balance you can achieve such type of security if you declare balance variable as private no other candidate can access your data directly only other person can access by using public method okay so this can be achieved by the encapsulation so by using encapsulation we can achieve the security that is nothing but data hiding as well so if you have any doubt uh difference between encapsulation and abstraction i have already uploaded one video or related to the topic okay you can go and watch in playlist okay the next topic is inheritance so inheritance is one of the major concept in object-oriented programming sentence is a technique you can create a new class by using existing class functionality that is nothing but inheritance so one of the main advantages of inheritance is in the real-time application we can reuse the existing code within the new applications okay let me take one example then you can understand how you can achieve a reasonability of the existing code see here class a contains some code here this code will be inherited by by creating new class by using extends keyword so if you use extends keyword that means we are inheriting we are acquiring all the features of a class a into class b okay this class a is nothing but super class our base class this class b is nothing but sub class or derived class or child class this class b contains its own methods as well as parent class matters as well okay so there are different types of inheritance are there like a single level inheritance multi-level inheritance multiple inheritance okay so i am not going to discuss about those things only what is the main functionality main working functionality here i am taking one real-time example like a class course in this class this course contains some features [Music] okay again i am creating new class that is professional course in the professional course i am creating my own functionality as well as i am acquiring course functionality as well i'm acquiring course features as well by extending by using extends keyword once you use extended keyword that means we are inheriting all the features of superclass to the subclass and and again i am creating one more class like a class non-professional courses i am extending course this parent class is already existing code this code we are using again and again according to our requirement that is nothing but inheritance main advantage of inheritance is we are using existing code again and again according to our requirement next one is a polymorphism so it is also one of the silent feature of oops concept then what is fall margin formulas means many forms are we can say that one method can take more than one form based on the type of parameters order of parameters or number of parameters in simple terms we can say that fall marks means many forms okay in real time example it can take a person a person can behave differently based on their location suppose a person can behave in office differently and in the market he behaves differently in the house he behaves differently okay so only one person can behave differently that is nothing but polymorphism so in java there are two types of polymers on there like a compell time for margin or runtime formats for comparative fall margin we can also call method overloading what is a method of overloading method overloading is nothing but method name same but their parameters are signature is different that is nothing but method overloading so let me take one example then you can understand what is method already so here i have taken a class calculator in the calculator class i have declared two methods here method names are same see here add add and the parameters are different you are passing here two parameters and you are passing three parameters okay this is nothing but method overloading okay one method can behave differently so by using this method we can add two values and by using this method we can add three values so method name same but parameters are different this is nothing but method overloading okay so this happens method overloading happens within the same class only we're creating the object for calculator class calculator cal equal to new calculator by using object reference we are calling the method so whenever you are passing two values this method will refer to the this method and whenever you are passing the three values and this measure will refer to the three parameters during combat time only so that is nothing but method overloading is also called compile time because it will call these methods it will resolve the methods during compilation okay i hope you got what is method overloading so so method overloading is method names are same but the parameters our signature is different okay so it might be type of parameters or number of parameters okay the order of parameters it may be different okay that is nothing but whether all right then what about method overriding another overreading is also called run type volumizing we are overrating super class method in the subclass that is nothing but method overriding so in the both the parent class and subclass both have same name and same parameters or same signature that is nothing but method overriding in simple terms i can say method overriding is we are rewriting the super class method in the subclass so using polymorphism we can achieve flexibility in our code because we can perform different operations by using methods with the same name according to our requirement then let me take one example then you can understand what is method overrated i have taken a bank class so in that class i have defined one method get interest okay so this is a static implementation based on a requirement we have to override this method in our child classes by creating new classes suppose i am creating a new sba class in the sba class i am overrating superclass method in the subclass so that is a different requirement okay so based on our requirement we are overrating so based on requirement we are overrating the super class method in the subclass that is nothing but method overrating our dynamic method as well our runtime polymer is also we are called so that's all guys if you have any doubts on this session please comment in the comment section i will reply to your queries and don't forget to hit the like button and also share to your friends it might be helpful to your friends also we will meet in the next video thank you for watching