OVERLOADING CONCEPT - JAVA PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel in today's session let's have a look on more loading concept right so in Java there are three types of warnings first one is constructor overloading next method overloading next operator overloading first let us see what is meant by overloading so going through the C language so we had different functions we can write the different user-defined functions outside the main function and if you are trying to write two functions with the same name but different parameters for example some add this is the one function and this is the another function into a comma int B so the logic is same but the parameters are different so the name is also same here the name of the function is add here also the name of function is end here there are no parameters zero parameters here we are having two parameters in the logic is same so if you are trying to write such type of functions with the same name and different parameters in C language it will not accent this is not supported in or C language right so no two functions must share the same name so every function must be having a unique name in C language let us coming to this Java programming in Java programming this type of concept is supported this type of concept that means implementing the same thing in different ways so that we call it as ball rolling so here the name will be same but there are letters will be different same name different parameters this is called over so this is of three types of overloading so that means Java supports these three types of global rulings one is the constructor overloading method overloading and operator over running so we know that a constructor overloading already we have seen that is we have seen different types of constructors so two types of constructors one is a default constructor without any arguments and the parameterised constructor so writing the constructor with some arguments right so based upon the object creation the particular constructor will be involved that means that particular contractor will be executed so that is for our constructor overloading constructed without arguments and this is para we trace the constructor that makes me there will be parameters we will pass some parameters and Metamora we've also seen so having the same name with different parameters operator overloading in Java we had one operator for the example of operating operator overloading that is plus symbol class so this is having this can be implemented in two ways one is addition operator another one is concatenation operator so the same symbol is used for two purposes one is addition other one is concatenation so implementing in different ways the same thing implementing in different ways that we call it as operative already so all these terms we call it as polymorphism so including the same thing in different ways so this polymorphism in our Java is achieved by implementing this overloading concept so that can be the constructor overloading or a method overloading or any operator lorilee right so this polymorphism you say hm by implementing this overloading concept and this this is called so everything will be executed during the compile time itself so this is called compile time polymorphism compile same polymer so so there are again two types of polymers do so compile time polymorphism and the content polymorphism and this is done during the compile time itself so that's why we call it as a compile time polymorphism so finally the compile time polymorphism is a is true by implementing this overloading concept now let us see one by one constructor method and operator overloading so give a simple examples for easy understanding so we know that our program can have in any number of classes that's why we will read one cast so some class yay right in the class we can have the variables and methods and first of all let us write that constructive so this is a constructor we know that a constructor is similar to the method it is also having the same name as a class name but it doesn't have any return type so if you write this return type this will be a method if you are not making the any return type this be treating as a constructor so a constructor month right so this is one I had I'm ready one more constructor with the parameters in a say I'm writing the transistor class now I have to write the main function okay so for that I am writing one more case so let us write the class here class C overload Class C overload public static void main arguments I have to create an object right so creation of object means class name the object obj1 is equal to new keyword and the constructor so here as we have giving the no parameters so this will be executed this plot will be executed in object two is equal to new a of some ten so here we are passing one parameter as in the constructor so it will search for the constructor with 1 parameter so this block will be executed Africa this object - right hope you understood so implementing the same constructor in different ways so with parameter and without parameter so that will search for this particular constructor right so hope you understood this one this is called a met the constructor overloading constructor overloading so we will see by implementing in the system also right now let us see the meta movie so similar some class a let us write the method just about the constructor write the method so for melting a method first we have to write the return thing so void some display system dot out dot println display next I am reading one more method with the same name say method name display in a system dot out dot println a is equal to plus a so this is a method both ox is the same the previously we have written the constructor and this is a method right now I have to create an object and I have to access this display so a obj is equal to new yeah so it will sense for this constructor there is no constructor for nothing will be happening so object is created now through this object we have to access this one obj dot display so this will search for this method with no argument so it will search for the method with no argument so this block will be created in UK next obj dot display some 30 that means we are passing one parameter here so it will search for the method to this one right so the same method with the parameters so it will search for this and this block will bring it executed that's it this is about the method so both are same right so previously we are not writing any return type so it is cancer it is treated as a constructor and here we are writing some return type and this is called a method so both are equal so we can find a one more method with the two parameters so we can write any number of methods but there must be a difference in parameters number of parameters and that should be accessed in main function hope you understood this method alone now we're going to see the constructor oh sorry operator over the third one so we know that we have seen just now in addition operator that is a plus is the operator overloading so plus can be used for both purposes that is addition as well as concatenation see it's building classic some into a is equal to five B is equal to six okay is that the instance variables let us write here here itself main function right here I have to access this one so I have become right the constructor yeah obj is equal to new okay now I will access this one so system dot out dot println a plus B is equal to plus Oh it out here press obj dot B C so just I want to add two numbers so two members have taken s instance variables so I am accessing these variables for using the object created by for this class so don't get confused let it let us write B in here that is right here B okay here we are taking a and B as a variables C C object and new seat sees a classmate right so here I am trying to add two numbers and printing the result so this will be as this it will be printed a cross B is equal to and Here I am adding two numbers or filtered a plus also don't be but here it will drink it as a concatenation so the output will be not the level it will print 56 if you write this one in such case it will consider it as a concatenation and you trade 56 so that in order to perform the addition we have to enclose this in parenthesis so if you enclose these two in the parents's automatically the result will be I hope you understood this one plus is used for both addition and the concatenation so if you have failed to write the parenthesis here it will treat it as a concatenation so if you enclose with this statement within the parenthesis it will treat it as an addition so this is on operator overloading now let us see all these things the constructor overloading operator overloading and the method overloading by implementing the programs in the system hi friends so now let us see the overloading concepts bible-reading a simple program so we have seen the three types of overloading so first one is constructor overloading then method overloading in the operator overloading first let us see that Transtech term overloading let us write a class with a constructor so I'm writing the constructor Here I am not writing any return type so it will be treated as a constructor so just I will display something right constructor without arguments and I will write one more constructor with one argument constructed with arguments right so I will close I will write one more this one C overloading constructor overloading or load I am writing the public main function I am creating a constructor an object by using the constructor so this will execute the constructor without any arguments and the next one I will create a one more object obj1 with one parameter some 10 so it will execute the constructor with one argument so whenever this object is created the control will search for this constructor name in the class so if it is there that particular block will be executed if it is not there nothing will be executed and if you create this line execute and here we are passing one parameter to the constructor so that the compiler the control will search for this constructor with 1 parameter in the above class so it fine if it finds automatically it will execute that particular block so let us say this and execute this C overload dot Java now let us execute this one C overload dot Java write Java C Overlord see trans factor without arguments constructor without me so first object we are writing we are calling the constructor without argument so it was displayed first in the first line and in the second line creating an object pricing with the parameter to the constructor so this one will be executed and everything will be done at the compile time itself so that that's why we call it as a compile time polymorphism so this is a constructor overloading concept constructor overloading so let us see the method overloading concept so just simple let us rename this one method overload dot Java yes so here we have to write a return type void add here also void add here we will take a two three I mean two parameters int a comma B and here so we will take a two parameters here also local variables two local variables a is equal to sum 10 we will directly they take these values B is equal to 20 and let us sum these two a plus B and let us print the sum so this is the code written in this function some is equal to right so the same thing we will write in different way taking two parameters as inputs in C is equal to a plus B so don't get confused these are the two variables in local variables in this method and those are the very local variables in that method so otherwise if you are confusing let's let us change the variable names X Y and all right so let us print the same thing system dot out dot println sum is equal to plus Z now let us create a one object so we can remove this one so by using that object call the method add so that the first method will be called object dot add we have to pass some parameter some 40 comma 15 so these two will be stored in X and Y and it will be performed so let us see this one let us execute this one Java C M overload dot java oh sorry yes so C was not declared just we can declare a C right so this clear screen Java em over so I am executing the class word not find romaine overload sorry yeah see sum is equal to 30 and sum is equal to 90 so far by by calling the first function this block will be executed because this is the method with no zero arguments right the control will search for the method with zero arguments and in the second line the controller will I mean the control will search for the add method with two arguments in the class so in fire if it finds it will execute that particular block so this is not allowed in our C programming that means no two methods or a user-defined function should not have the same name so here it can have a same name but different parameters with the different parameters it will be accepted it is supported right so this is all about the method overloading now let us see the operator operator overloading that's a very simple thing so let us see just let us write a function so let us take variables a is equal to some 10 B is equal to some 30 some in C is equal to or directly we can write hit system dot out dot println let us take sorry a plus B is equal to plus a plus B so a plus B means generally we have to get the output so let us write the main function in this in the same thing static void main string or domains let us create so let us take Opie operator overloading Opie obj is equal to nu Oh people think so let us call this function add let us say this Opie dot Java now let us execute this one so this is also just a program for addition of two numbers so we are calling the function in the function we are taking two local variables and we are trying to add those two local variables in printing the sum right so let us see the output Opie dot Java right what is the result a plus B is equal to n 30 because here 10 and 30 here this plus is treated as a concatenation operator so it is treating it as a concatenation operator plus is treated as concatenation so if you enclose this a plus B in the parenthesis then it will treat it as a addition operator so our output will be a plus B is equal to 40 so hope you understood the difference so in the absence of parentheses it will be created as a concatenation operator so 10 and 30 n and 30 are concatenated so 10 30 it will be printed so if you enclose them in the parenthesis automatically those two will be get added and the result will be displayed right so this is the operator overloading so the same operator where the implementations are different so in one logic we are using the plus S of concatenation in another logic we are using classes in addition operator right so let us stop here hope you understood this operator overloading concept so method of overloading constructor overloading and operator overloading so this is called I mean by implementing this we can achieve the polymorphism that is compiled and polymorphism right if you really understood my sessions like my sessions and share my sessions with your friends and if you are having any feel free to post your doubts in the comment section so that definitely I will try to clarify all your doubts and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 102,851
Rating: undefined out of 5
Keywords: sundeep, saradhi, kanthety, java programming, java basics, java fundamentals, beginners, programming fundamentals, java faq, bytecode, java introduction, object oriented, oops, oop concepts, set classpath, abstraction, inheritance, polymorphism, encapsulation, class, object, virtual machine, java compiler, program execution, multithreading, method overloading, method overriding, javac, class file, constructor, operator, early binding, static binding, compile time
Id: KqAXwUcMR9M
Channel Id: undefined
Length: 29min 5sec (1745 seconds)
Published: Sat Jan 12 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.