 So this lesson we start with object oriented programming in Java language and the agenda of this lesson is to have the introduction to object oriented programming and also about the class and object. So what is this object oriented programming? So it is a programming paradigm is nothing but how we can develop an application. So my requirement is I want to develop a project, a banking project. So what methodology which I am using? So it may be either procedure oriented programming, POP, it can be object oriented programming OOP or it can be aspect oriented programming AOP. So any program if you talk about every program may contain mainly two parts. One is data and the other one is function or method. So this procedure oriented programming is based on data as well as function. But the data and the functions are treated separately that is what procedural oriented programming. So procedural programming is about writing procedures or methods that perform operations on the data. So data is one part and method is another part it is treated separately whereas in object oriented programming it is about creating objects from the name itself we can understand. Object oriented programming this type of programming is purely based on object. So it is working with the data and methods together. It contains both the data and the methods whereas procedural oriented program. So data is one part, method or function is another part. So if you are having a global variable you consider a C programming language. When you write a C program that C program may have global variables. So that global variables can be accessed by all the functions because data is separate function is separate so that data can be accessed by all the function there is no security for data. By so many lines of code you need to write. And this object oriented programming is a programming paradigm based on the concept of objects which can contain the data in the form of fields often called as properties or attributes or we call it as member data and the code in the form of method. And this object oriented programming is purely I mean it is based on class and objects. So all object oriented programming have got so many other features principles like inheritance polymorphism encapsulation abstraction but mainly object oriented programming is based on two things one is class and another is object. So what is a class in object oriented programming? A class is a concept or class is a blueprint using which an object can be created. So what is a concept for example if I ask you what is a car when we say what is a car we know that a car every car have got a registration number car has got an engine number a car has got a model so 2020 model 2018 model which model is that car has got color fuel petrol or diesel is required. So clutch brake accelerator so these are all the properties of a car that is what we talk about a concept. So what is a car so we know car has got these properties like registration number engine number model color clutch brake accelerator these are all the items and also a car have got different functions. So we are able to start the car we are able to accelerate the car we can reverse the car so these are all the functionalities. Now for example you see starting a car a function a method or accelerating a car or reversing a car to perform any of this operation what is required an item is required which item one item petrol or diesel is required so a class is a concept a concept contains items and functionality and each functionality of an item is used is using a particular property or particular properties. So an item of a concept is used by performing a particular function a class is something like that a fan a computer so whatever things are there in the real world if you talk about it has got only two parts one is the items of that and the other one is functionalities of that. But coming to a programming language like Java a class is a user defined data type in Java we have got eight primitive data types like byte short int long flawed double char boolean these are the eight primitive data types of Java but if I want to develop a MIS project management information project I need to store the employee details so I need to have some employee so we know that every employee have got employee number name of the employee designation of the employee salary of the employee address of the employee etc. number of dependents the pan card details social security number bank details blood group all these properties will come for an employee. But this type of data is not available in Java so Java has got eight primitive data types but we want to create our own data type of type employee with this employee number name designation salary address and some methods or suppose if you want to develop a banking project so in a banking project what type of data is required different type of data is required but mainly we require account type data so that account type data what all things basically it comes every bank account have got an account number the name of the account holder balance amount it is not that contact number email ID address of the person gender of the person all that things will come but in our example we take account number name of the account holder and the balance amount and what are the functionalities we are able to withdraw the amount withdraw the amount from my account we are able to deposit the amount so the balance amount is being affected so withdraw or deposit function is using the amount balance amount so this is what we talk about a class so class is a user defined data type Java have got primitive data types but to develop an application to develop a project we need to have our own data type like employee like bank account like a ticket so we develop a ticketing application a bank a flight ticket application so ticket have got PNR number the name of the passenger date of travel time of travel from which airport to which airport which flight all these properties comes and it has got the functionalities also now when you talk about an object we seen an employee so we created an employee type data that is what class now I am an employee so my name is Sunil I have got my own employee number I have got my own salary I have got my own designation so I am an employee type so what is an object an object is the real instance or living instance of a class an object is created from the definition of a class a class is a blueprint from which individual objects are created so we discussed about a car when you see a real car on the road if you see a real car we can say that car that particular thing this is a car we say that if I ask you by pointing to a real car if I ask you what is this you say this is a car why we are saying that this is a car because it is it has got all the properties of car type car we know what are all the properties it has got what all functionality everything is available on that physical thing so we say this is a car we can have any number of objects also now when you see an employee we know employee number employee name designation salary address so we can create multiple object for example you see so four people so this is employee one the other person is employed to the same way other two employees so EMP 1 EMP 2 EMP 3 and EMP 4 we call us objects what type of object they are they are all type of employee type object because every employee have got their own employee number employee name designation salary address each person have got their own thing these are all real employees so this person the first employee have got his own employee number the first person have got his own name his own designation his own salary his own address this is what we talk about an object as a syntax when you see how to create a class a class is created by using the keyword class followed by the class name inside this block a class may contain properties or attributes or member data any name and also it has got functionality and how to create an object or it's not that only this a class may contain fields that's nothing but properties or attributes or member data methods but in a real class we can have constructors class can have block a static block or it can have initialization block we see that and a class may contain other class a class may contain some inner interfaces also that's called as nested class or nested interface a class can be defined inside another class all these things may come inside a class then to create an object new keyword is used for creating an object I want to create one employee so new what type of object employee type object so new object time that is what the object and it is identified with a reference so object type object reference is equal to new object type as an example new employee is the object and its references employee EMP to identify that object so I am an object I have got my own employee number my own official name my own address I have got my designation salary all that things I have but I am identified with my name that name is nothing but the reference the pointer to its memory so when you see the physical structure of that so one example when you see employee have got EMP and no employee number integer type employee name string type salary float type numbers with the decimal point so we created a class called employee no methods we defined now we are creating an object employee EMP or employee Sunil is equal to new employee when you say new employee a new object is being created where the object is being created in the heap memory so in the JVM Java runtime and Java runtime environment or Java virtual machine jre contains JVM Java virtual machine so it has got an architecture it has got different memory for example in our house we have got different rooms one is drawing room bedroom dining room kitchen study room computer room so different area each area is for one or the other purpose the same way in the JVM architecture it has got different memories one such memory is called as the heap memory where all the objects are being placed so one memory heap memory this employee contains what EMP and no ename and sale so when you create an object of employee so memory is allotted in the heap it will have three locations for storing its employee number EMP name and salary of this object new employee then what values will be given by default each member data will be assigned with its default values EMP annoys integer type so what default value will come zero integer is zero is the default value EMP name is string type the default value is null and salary is float type the default value is 0.0 so new employee work is over in the heap memory one object is created second object another place so I am an employee my employee number my name and my salary is specific to me me is nothing but object reference so new employee this is happening and this EMP is the reference that reference is coming in another space another room stack memory EMP is pointing to this particular location so this EMP have got EMP anno EMP name and sale so if you want to access that properties of this EMP using this EMP object is this that can be referred with reference with EMP so we can access it by using EMP dot EMP anno EMP dot E name not actually name EMP dot EMP name actually it is E name and EMP dot sale that is the way we are accessing that now we will see this one in a practical way hope you are clear with this one happy learning in this practical lesson we are going to implement the previous lesson thing so practice the same example we are going to implement we create a class called employee we just got three properties then we create an object then we will access the properties by using dot operator so for that purpose let's create a new directory in C drive I am creating a directory with the name of Java so I created a directory and there we want to write our programs so to write a Java program we can go for any of the editors you can use not pad or not pad plus plus or edit plus in the next lesson we will see how to do this project in eclipse IDE so I am just opening this edit plus we write a new Java program and the Java program we call the classes employee and it has got the main method a standalone Java program have got the main method so we provide the employee number integer EMP anno string name of the employee and float salary of the employee now inside this we are creating an object so create an employee object employee type object create an employee type object so we know the way of creation new employee object is created and it is referenced by EMP so employee EMP or any reference can be given so we created an object after creating the object we want to access the properties access the EMP employee object properties with reference using reference so the reference is nothing but EMP so EMP dot EMP anno EMP dot EMP anno then a separator I am using a concatenation then a separator so we will get the output us by default what what values are coming so the values are nothing but EMP dot EMP anno will be 0 EMP dot E name will be null and EMP dot sal will be 0.0 so with a separator we want to display so plus concatenation EMP dot E name plus a concatenation a separator EMP dot sal let me save this program in our folder C drive we created directory Java and we save this program as employee dot Java so we got employee dot Java let us save this so in our folder we got employee dot Java C drive Java folder contains employee now we need to compile it so we are compiling this in the command prompt start button CMD let us come to C drive CD slash come to Java directory change directory CD slash is coming to the parent directory CD Java there we got a program called employee dot Java so let us compile this Java C employee dot Java so this course is introduced for the people who are already aware of Java how what is a standalone Java program how to write a Java program so that if you are aware for them so cannot find symbol what is error EMP dot EMP anno EMP dot E name but what is that property we given name so actually it is E name see MP have got E name so we are accessing that now save it compile the program so error cannot find symbol EMP dot E name so that employee class is not having EMP E name property it was having name we changed it into E name now you compile so whenever you compile a Java program it is creating a dot class file employee dot class now let us run this Java employee so let us run this program Java employee we are getting the value 0 null and 0.0 so this is what we have seen practically so we have got a class in the main method we are creating an object of that class then that object properties we are accessing hope you are clear with this one happy learning so in this lesson we are going to see the previous thing with the eclipse so how to create an object so employee object we will create in eclipse and also we will see what are the different ways we are able to change the state of an object so EMP object the value of EMP anno value of E name and value of sale is what we call it as the state of an object so every object is associated with a state member data values methods that means behavior of an object and also identity so state behavior and identity now in order to change the state of an object it can be done by using the reference it can be done with the help of method and also by using constructor so let us create a program in eclipse so we got our eclipse environment so in this sit project creating a new class right click new java class and the class name is employee employee is the class name and we want to have the main method we are including main method starting point of a java class in this main method so employee class we are providing the properties EMP and no then string E name or name then float salary these are all the properties now we create an object of employee same example what we done in the previous lesson so employee is equal to new employee then after creating the employee object let us access its properties system dot out dot print ln to display system dot out dot print ln EMP EMP anno plus separator EMP dot E name plus a separator EMP dot sal now let us run this program so let us right click or run on this icon when you run this application we will get the output in the console 0 null and 0.0 now first thing is to change the state of an object changing the stage changing the stage of object using reference so which is a reference here EMP so that EMP dot EMP and no is equal to 101 EMP dot E name is equal to Sunil I am providing the name of the employee as Sunil EMP dot sal is equal to maybe 2500.5 F a floating point value so employee number employee name and salary with the reference we are changing it was actually 0 null 0.0 now let us display this again so let me copy that statement then save this and run this program the same employee object it was 0 null 0.0 let us run this and see what happens it becomes 101 Sunil and 2500.5 in the previous lessons we seen the memory structure EMP and no E name and sal was given with the default value 0 null 0.0 but we are changing the state of object using reference now if I want to display that what we can do is a class can have properties three properties or member data or attributes one method a static method and also we can have a normal method void written up is void display properties display properties is name of the method so what is this method to do every method is used for performing some operation what operation this method is going to do it is only going to display s out control key and space bar shortcode it is going to display the employee number then a separator E name which object is calling that objects employee number employee name as well as salary will be displayed so this is one method so in this case you don't need to write like this if you're not writing only one time we'll get the employee number name and salary of that employee now using that object EMP dot display properties EMP dot display properties the control will come to this method and that objects EMP and no E name and salary will be displayed so run this we are getting that value now the second way to change the state of an object changing the state of object using a method so in that I don't want to change the employee number I just want to change the name of the employee and salary of the employee for that purpose we define one another method void set properties set properties directly we are providing EMP and no equal to no EMP and no I'm not going to change only E name if you want you can change also E name I'm giving it as Naveen and the salary also we are making it as 5000 f a floating point value or directly 5000 also integer value can be assigned to float variable so we are changing the E name and salary value so let this object call set properties method EMP dot set properties when it calls the set properties method control will come to this method and it execute these statements so that in the memory of EMP in the heap memory EMP and no will be 101 only Sunil value will be replaced with Naveen and 2500.5 will be replaced with 5000 let us call that method to display the details again so display properties we are calling again second time run this program when you run this what is that we are getting the output zero null 0.0 changing the state of object by using the reference and changing the state of object using a method and the third way of changing the state of an object is by using constructor that we'll see in the coming lesson happy learning this lesson is about constructors in a class so what is a constructor constructor is a special type of method of a class normally a class contains properties and methods a constructor special type of method and we know every method should have a name so if I constructor the name of the constructor method is same as that of the class name so if my class name is employee the constructor method name also should be employee and a normal method will have a return type void display details void is a return type that tells that it is not returning anything but a constructor method is not having an explicit return type so the major difference between a constructor and a normal method is a normal method should have a return type void deposit or boolean withdraw so that boolean and void are the return types but a constructor two two things the name of the constructor is same as that of the class name and it should not have an explicit return type if you write the return type then it becomes a normal method the fourth point a constructor is used to initialize the member data of an object the purpose of a constructor to give the default values for the member data of an object and when a constructor get executed a normal method if you see that get executed whenever it is being called by an object so emp dot display details so emp object is calling the display details that time it will get executed and a normal method can be executed any number of times can be called any number of times but a constructor is called when an object or an instance of a class is created and every time so whenever you create an object of a class using that new keyword at least one constructor is called there may be a possibility that two constructors also may gets called through constructor chaining but for sure one constructor will get executed at any cost and the constructors are of two types one is called as default constructor or zero argument constructor and constructor with arguments or parameterize constructor use a defined constructor and compiler define constructor that's what default constructor so what is basically a default constructor compiler defined constructor see just imagine we created a class or we return a class class account in our program and we have not defined any constructor with a method with the name of the class no return type we have not written so when you compile that program java compiler will create a constructor of its own that constructor is called as a default constructor java compiler provides a default constructor at the time of compilation by default if no constructors are written in the class so if there is no constructor in a class compiler automatically creates a default constructor for example I written a class called employee or a class called account so this we have not written any property or any method that we have got when you compile this program it creates employee dot class and in that employee dot class it will create a class file it contains not account it should be employee constructor it will have employee so this is mistake so it will have employee constructor so we will see practically so let us create a class so inside our edit plus I write a new java program with the name of account so creating a java class with the name of account no main method also an empty class and I save it as account dot java account dot java is a program so let's compile this program dir in the previous lessons employee dot java employee dot class and we compile this java see account dot java account dot java we compile remember there's no properties and there's no methods if you want to see it has got account dot class a bytecode file is being created and if you want to see the contents of that java p java profiler and you just provide the name of the class it will show you whatever properties what all methods what all constructors are there inside a class it will show I present java p is nothing but java profiler when you see the java class no contents are there available inside but when the program is being compiled class account compiled from account dot java but what is that we can see we can see a constructor account without having any parameter so constructor a special method of a class name of the constructor method is same as that of the class name and no written type so this is a constructor and when it is created at the time of compilation compiler created that that is called as a default compiler a default constructor so java p when you say java p employee this employee class also have got a constructor cmp no name salary this constructor but we have not defined that constructor we were having only main method but the compiler have created a constructor so this main method return type is void but employee a method no return type at all so that is what we talk about a constructor so the mistake here is it is not it should be class employee or the constructor will be employee now one example when we see you see we got a class employee class have got three properties empno name and sal we defined a constructor you see a method a special method name is same as that of the class name no return type if you provide the return type void employee then it becomes a normal method i just returned some star system dot out dot prindal and five stars used to initialize the member data of an object and it has got a method the normal method display details so display details is a user defined method a normal method but this employee is the constructor why it is called as constructor a method name of the method is same as that of class name no explicit return type so when this method get executed whenever an object of a class is being created now what we do is we'll have constructor test in this constructor test that contains employee class also constructor test main method creating three objects new employee first object again new employee second object new employee third object so whenever you compile this program java see constructor test dot java you compile it compiler will create constructed test dot class as well as employee dot class and when you run this program java constructor test if i press enter what happens the control will come to the main method then the first line of code is employee emp1 is equal to new employee creating an object so when we create an object a constructor method employee with no parameter this is also employee with no parameter a constructor gets executed automatically whenever an object of a class is being created so first line so that time control will come to the constructor and in the constructor four lines of code the first line is system.out.println of star so we are getting the value star first star then emp1's empn no becomes 101 emp1's name becomes sachin and emp1's salary becomes 2500.0 that is happening in the memory it's not displaying anything now the next line of code again object creation so what will happen new employee it will call the constructor it will display this and emp2's empn no name and salary becomes same so we'll see the output is star then the third also object constructor is called so from this we can understand a constructor will get executed automatically whenever an object of a class is being created and it is used to initialize the member data three objects are created automatically it is calling the constructor we got this now emp1.display details so what happens it will call this display details and empn no name and sale of emp1 will be displayed then the second one emp2.display details again this method will be called and we are getting the value and then the third object is also calling so we are getting these values this is what constructor let's see this practically so in our eclips already we got class employee so what I do is I'll take this one and we write or we create a separate program new same program a java class constructor test constructor test main method we have now already we got this employee.java a separate program so in that employee.java what changes we do is we provide in the place of such properties we just define a constructor for our understanding I just write sout system.out.println some five stars we are giving five stars so empn no is equal to 101 so emp name in the presentation it was name we given it as ename ename is navine and salary 5000 5000.0 will be assigned to that so this is what we talk about the constructor zero argument constructor zero argument constructor so in this case we defined the constructor so compiler will not create a constructor of its own its own now the main method I am removing from here let me have the main method so we defined a class here so class employee constructor and display properties in constructor test.java creating create three employee type objects so employee emp1 is equal to new employee the first employee object we are creating the same way the second employee object we are making a copy of that second employee and the third employee so three employee objects we are creating say employee dot class employee class and constructor test dot class let me run this what will be the output three times five stars are being coming from this example we can understand whenever we create an object this constructor will be called and each object can call display properties method so emp1 dot display properties emp2 dot display properties and emp3 dot display properties now each object properties also run as your application we are getting the value so this is what we talk about constructor so two type of constructors one is default constructor zero argument constructor but not this so what constructor created by the compiler is called as default constructor and the compiler will create a constructor only if no constructors are available in the program in the class so here compiler will not create a constructor whereas for constructor test compiler when you when it is being compiled it creates the main method as well as it creates a default constructor hope you are clear with this one happy learning this lesson is about overloading methods so what is basically overloading methods or method overloading is a feature that allows a class to have more than one method having the same name with the different signatures so when we write a class a class we know that a class can have constructors class can have properties class can have methods and every method basically three things are coming one is the return type of the method the second name of the method and the third one parameters these are the three things required for any method so return type name of the method and argument details see in a class if there exists more than one method with the same name but with the different signatures are called as method overloading so what do you mean by method signature name of the method together with argument details is known as method signatures see for example every standalone java program have got public static void main method with the string array one argument so what is the signature of this main method name of the method is main together with argument details how many arguments are there one argument what type of argument is that string array so main with one argument that is string array is what the method signature of main method the next method is about add num so add num method have got two integer parameters return type is not considered at all when we talk about the signature so add num name of the method with two integer parameters so the name of the method together with parameter details is known as method signature the method calling signature so method means two things will come one is method definition what that method have to do and the other one is method calling so whenever a method is being called then only it will get executed so method calling signature should be matching with method definition signature and in a class it is not possible to have more than one method with the same signature so return type can be anything so in the method signature return type is not considered at all name of the method together with argument details so I cannot write suppose in our class we have got main method add num method with two integer return type is int so I cannot write one more method the return type can be anything void add num again with integer x comma integer y is not allowed so overloading methods are nothing but in a class if there exists more than one method with the same name but with the different signatures so name of the method together with argument details and this overloading may happen in two ways one is by changing the number of arguments so in this add method the signature is add with the two integers the next add method is add with the three integers the number of arguments the first add method have got two arguments the second add method have got three arguments that is one way the signature I mean method overloading is happening the other way method overloading is happening by changing the data type of arguments so in a separate class we have got two add method number of arguments are same two but what is the type the first add method two integers second add method one integer and a flawed value so the signature the type is different so number of arguments or by the type of argument this is what we talk about method overloading let us see an example let me write a program a new java class we call it as overloading test so in this class itself overloading test we need to have the main method and we define one method so main method is already there void add num it takes no parameters add num we write here s out add them with the zero arguments so add num with zero arguments or parameters this is one method so what's the signature of that add num with no parameters then another one I've got add num with integer comma integer so first one is no parameter the second add num we are having with the two integers s out we will say add num with the two integers so you can write the business logic also add num with the two parameters add num with the two parameters then one more add method add num method void add num with an integer x comma flawed so I cannot write one more integer method so we are we cannot write one more method with the same signature so add num into x and into y and this also index into y duplicate method add num even if you write the return type it will not consider you cannot define more than one method with the same signature in the same class so void this we may provide it as flawed type so now there won't be an issue so add num with two parameters add num with two parameters int and float so we have got int and float whereas here int and int so we define three methods when you see this overloading test class we have got three methods add num with no parameter add num with the two integers add num with an integer and a floating point value and also main method now we want to call that method so we will create an object of overloading test obj is equal to new overloading test so we are creating an object of this class that will say obj dot obj dot add num 10 comma 23 f so what is the signature of this method calling this object is calling add num method with an integer and a floating point value so which method will get executed so method calling signature is add num with the two I mean two parameters first is an integer and second is a floating point value so when you call this what will happen it will call this particular method method definition signature is matching with that let us save this run this program run as java application and see what answer is coming add num with the two parameters int and float now again obj dot add num so I am not passing any parameters so what is the signature of this add num method add num without having any parameter so which method out of these three add nums which method get executed add num with no parameters will get executed so run this add num with zero parameters now the same way if you want to call this add num method with the two integers what is that we do obj dot add num 10 comma 20 so what is 10 and 20 10 and 20 are integers so it will call the second add num add num method with the two integers will get executed so this is what method overloading so it will give more readability so the same method but the functionality may be different so add num without having any parameter will have one functionality add num with the two integers may have another functionality add num with the two parameters first is integer and second is float have got some other functionality so for that purpose we are using method overloading the next point we need to understand is there is some more one more thing called the type promotion so what do you mean by type promotion so when you see type promotion for example the same example itself i'll just comment it i'm not giving all these methods so what i told before is the method calling signature should be matching with method definition signature now for example i have void add num same method integer x comma integer y we just give a message s out inside add num method so method calling signature should be matching with method definition signature we can use the same program itself now what i do is i have two integers int x is equal to 10 int y is equal to 20 we call obj dot add num 10 comma not 10 comma 20 we will say x comma y so what happens now add num method is being called by passing two integers x and y are two integers rather than writing this let's provide a proper output also so int n or sum is equal to or long sum is equal to x plus y or int sum is equal to x plus y we'll say x plus plus symbol x plus y x plus plus y concatenation equal to we want to display the sum sum is being displayed now what happens now x value is 10 you can give it as not x you can give it as any variable name a and b we are calling add num method by passing a as well as b so coming the control will come to add num method x value becomes 10 y value is 20 so method calling and method definition both are same say x plus y 10 plus 20 sum becomes 30 so x value 10 plus this is concatenation operator so that integer is concatenated with a string plus will come as it is plus y value plus equal to sum let's run this 10 plus 20 is equal to 30 we give an integer time now just imagine this b is of a byte type so b is byte so when we are calling this add num method we are passing an integer and a byte variable but do we have a method definition with integer and byte no but still it is not showing any error so we are calling the method by passing a is of intertype and b is of byte type so we should have a method definition with the integer and a byte so for example if i make it as byte there won't be any issue program will work and even if it is not so now the method calling signature is same as that we defined in this method let us run this 10 plus 20 is equal to 30 but i'm just converting this to short type still it is working so that means what is happening type promotion is happening data type promotion is happening what is that one type of argument is promoted to another type implicitly internally one type of data is converted if no matching data type power is found in the method definition byte data can be promoted to short into long float or double so if the data is byte it can be promoted to short into long float or double short can be promoted to into long float or double character can be promoted to into long float or double float can be promoted to double long can be promoted to float or double this is what we talk about data type promotion so if you already seen that example so add num int x so byte is promoted to short it is working byte can be promoted to int working byte can be promoted to long but there may be an error here so int sum is equal to x plus y x is integer type y is long type when you perform some operation with integer and a long it returns a long type value it returns long type value because at addition we are performing with an integer and a long type data so it returns long if it is integer and a float it returns float type if it is integer and double it returns double type so now let's run this we are getting that so this is what we talk about type promotion a byte can be promoted to short or int or long or float or double an int can be promoted to long float double etc so you can give long so this is what we talk about type promotion so one type of data can be promoted to another type implicitly now for example in this one if we have got an add num method with an integer and a byte so we got add num with int and a byte variable byte b or byte y so in this case which method will get executed when you call this we are calling add num method with an integer and a byte so it will execute surely this add method with the integer and byte only so s out sum is equal to we give the value x plus y sum is equal to x plus y so which one will get executed run this it will execute the first method sum is equal to 30 but if you call obj dot add num if you say 10 comma 20 separate if you are giving what is this obj dot add num int and int so it will execute the second method so an integer cannot be promoted to byte but integer can be promoted to long so let's run this this case 10 and 20 are integers so runners you have application we are getting this 10 plus 20 is equal to 30 so what happens in the first case is it is calling we are passing an integer and a byte we already got that method the second case when we are calling add num method is being called by passing two integers 10 and 20 both are integers so it will call a function with integer integer integer is not there then it will see whether that any type promotion automatic type promotion is happening yes index and long while the second argument integer is promoted to long this is what we talk about method overloading as well as type promotion happy learning so this lesson we are going to talk about overloading constructors or constructor overloading so what is basically constructor overloading in a class if there exists more than one constructors with different parameter list so class contains more than one constructors with different arguments is what we talk about constructor overloading as an example if you are having a class called student the student have got three properties student id student's name student age three properties and we have got three overloaded constructors based on the requirement the respective constructor get executed so student with no parameter one constructor with the two parameters integer and a string and the other constructor with the three parameters integer string as well as age I mean integer integer string as well as integer so we will just see this in a practical way so in our practical example we are going to talk about employee class so we will create our main classes overloading constructors so overloading constructors contains the main method and also we have got another class in the same program we have got another classes employee so class employee contains three properties integer emp and no so spring name ename and as well as float salary are the three properties so we are going to create three objects so we are going to create three objects of employee so employee emp one the first employee reference is equal to new employee this is what the first object is the same way the second object we are creating with the employee number and the employee name okay now we will create three employee objects and the third employee emp three three employee objects so anyway by default the constructor will be available by the compiler or if you want you can create your own constructor employee with no parameter constructor with the zero parameters and also one method get details is one method to display the details of the employee so get details method to display emp and no as separator we are giving then the name of the employee ename separator plus salary say employee number employee name as well as salary so class employee contains three properties one constructor without any parameter so whenever you create an object so we are creating three objects so three times the constructor will be called then emp one dot get details calling the first the first object is calling get details the second object is calling get details and the third object calling get details so we have got three objects and three objects each object is calling get details method so we know what output is coming by default the state will be zero employee number employee name and salary so zero null and zero point zero is coming by default all these three objects calls the constructor without any parameter employee with no parameter this constructor now just imagine the second object is providing the integer value as well as a string value so the second object is being created by passing an integer and a string but we don't have a constructor with an integer and a string that is why the error is coming here so when you run this what error is coming a compilation error errors exist in this required project proceed what is the error the constructor employee with an integer is undefined so clearly the compiler is telling that you are creating an object of employee with an integer and a string but the respective constructor is not defined so we should have a constructor for employee class integer a and string b so when you define this the error is gone this is the second constructor now the error has gone previously error was there now the error is gone so a value is assigned to empno is equal to a and ename is equal to b b value is assigned to ename so when you create the second object new employee 101 and sunil the control will come to this constructor a value becomes 101 b value becomes sunil and that values are being assigned to empno of emp2 then b value that is sunil is assigned to ename now when you run this emp2 let us run this program now there won't be any error first object and the third object employee number employee name and salary is 0 null and 0.0 but the second object employee number is 101 employee name is sunil and salary 0.0 this is what the second object now we got two constructors with the different parameter list the first one employee with no parameter second one employee with an integer and a string now for example the third employee object 102 the name of the employee we are giving it as navine and the third employee object i mean this one and a salary also we are providing 2500 f a floating point value now the error is coming so there is no constructor with the three parameters integer string and a floating point value so we should have one more constructor i make a copy of this we define one more constructor same constructor is not allowed same signature will say into c now salary is equal to c so in this class employee contains three properties as well as three constructors employee with no parameter employee with the two parameters and employee with the three parameters this is not integer it should be float type that should be float type so that was the error before now there is no error so a value is assigned to emp and now b value assigned to ename and c value assigned to c so emp once employee number employee name salary will be zero null 0.0 because we are not giving any value of our own so the default values will be given at the time of creating an object itself when you create the second object it will be initialized with the zero null 0.0 then after that the constructor will be called a value will be 101 b value is Sunil that is assigned to emp and no ename the same way third object so this is an example of overloading constructors the first object second object we given the employee number as well as employee name salary default value and the third object corresponding state is coming now let us see one another case what change I do is a and b are the variables declared in the constructor whereas emp and no and ename are the variables declared in the class so these three variables are called as instance variable they are called as instance variable and the variables declared inside a method or in a constructor that's called as local variables so one is instance variable the member data of a class is called as instance variable and the variables declared inside a method this particular parameter or in the main method emp1 emp2 emp3 these are all declared inside the main method so that local variables can be accessed only within that and the instance variable normal member data two type of variables now instance variable as well as local variable now just imagine in the place of a I'm giving emp and no in the place of b we are giving it as ename so now what is this emp and no and ename these two are local variables this is local variables of this constructor whereas what is this two instance variable or three instance variables so a to be replaced with the emp and no b to be replaced with the ename now what happens here is when you create the second object 101 and Sunil that values will be assigned to this emp and no and ename emp and now becomes 101 ename becomes Sunil but here this is local variable this one also local variable so we are just assigning the value to the same local variable we have not assigned it to the instance variable in the previous case when we have given a and b second object value was 101 and Sunil 0.0 but now when we create this object the employee number employee name and salary will be 0 null 0.0 and no changes are happening in the constructor what is coming here the assignment to variable emp and no has no effect yellow colored it's not giving it is an error it's giving it as a warning the assignment to variable emp and no has no effect now when you run this what is the second object employee number 0 but actually we given 101 and Sunil what is it coming no why because we have not assigned these values to the instance variable it is only local variable so what all variables are declared in a constructor or in a method that is called as local variable and the member data are called as instance variable so this local variable value should be assigned to instance variable so to tell that we use a keyword called this a reference variable of Java a keyword of Java acting as the reference of the current object which object is that that object is nothing but this for example my name is Sunil Sunil Joseph so when somebody else is calling me they call it with call me with my name Sunil Joseph but when I talk about myself I say I or me the same with this is a keyword or a reference variable acting as a reference of current object now this emp and no which I selected is a local variable and this dot emp and no becomes an instance variable so local variable value is assigned to instance variable let us run this employee number is coming same way this dot ename is equal to ename so run this we will get the correct answer the importance of this 101 Sunil salary is 0.0 it's always a good but now why we don't need to write this dot emp and now here because there is no local variable with the name of emp and no a is a local variable but emp and no there is no local variable with the name of emp and no so it will be treated as instance variable so a local variable value is assigned to instance variable but it is always a good practice to represent instance variable with this dot it is always a good practice to represent local variable with this keyword so So it's sure that it will be an instance variable. So let's run this. We are getting the correct answer. Now, when you see another use of this keyword is to refer the instance variable and also to call the methods of the class. And another use of this one is in the second constructor we say this.empno equal to empno. This.ename is equal to ename. The same logic only what is happening here also. So repetition of code is happening. Rather than repeating that code, what we can do is, from this constructor, now you see the case of the third object. New employee 102, Naveen and salary. It will come to this constructor. Now we given only the value for salary. When you run this, only the third object salary will come employee number and name will be null. But that logic is already defined in the previous constructor. So what I can do is, I can call the previous constructor or constructor by passing A and B. This is called as constructor chaining. So constructor one constructor is calling other constructor. This of A comma B. A is integer. B is string type. So we already got a constructor. So this should be the first statement. This of A comma B constructor chaining. So what is the flow of execution? When we create the third object, new employee with the three parameters, control will come to this constructor. There what is that we are doing? It is calling this of A comma B. It will call this constructor. So this is what this keyword. And it's a must. In some situation, if the local variable name is matching with the instance variable name, to differentiate the local variable with instance variable, you should use, you should represent with this keyword. So what is the role of this? This is a keyword or reference variable of Java that refers to the current object. This can be reused to refer the current class instance variable. This can be used to invoke current class method. This dot display details. And this can be used to invoke current class constructor. This with parameter. That's what we call it as constructor chaining. Hope you are clear with this one. Happy learning. So this lesson, we are going to understand a banking application based on the concepts with that, what we studied in the previous lesson like class object, constructors, method overloading, all that. So based on that, we are developing a banking application, a simple application. So there we have got a class called account. So what are the details that normally comes in an account class? If you have got some properties like account number, name of the account holder, as well as the balance amount, as well as the functionalities are deposit. Along with the existing balance, this amount what we are passing to be added. The second one is withdrawal function. So there we should be able to, if the amount is sufficient, the balance amount is sufficient, we want to withdraw that amount. That means subtract the balance with this, from this, I mean from the balance, this amount to be subtracted. And if the account is already created, show the details also. So this is what our account class. So first let us implement our account class. So inside the same project in Eclipse, creating a new class with the name of account. So inside this account class, we have got three properties. So that properties are nothing but account number, name of the account holder and the balance amount. And the functionalities are deposit, withdraw and get details. So this is what the code we are writing. So our class contains three properties, account number, name of the account holder and balance. We got a default constructor and a parameterized constructor. So with the account number, name of the account holder as well as the balance amount. So this dot account number, so this is nothing but the constructors we have. So we got two constructors we defined. So one is constructed without any parameter or argument, then constructed with the three parameters. It shows the account number, name of the account holder and balance, long string and float, created an account. Then what are the functionalities? We got deposit method. We pass a floating point value. What is the logic of that? From the, along with the existing value of the balance, this amount to be added. So normally when you deposit some amount in bank account, you will get an SMS saying that so and so amount is credited to the account and at present the balance is what we are just displaying that in the console. Then the next method is withdraw. Withdraw some amount. So if you want to withdraw the amount, what is the logic? The requested, I mean, the amount which you want to withdraw is it is sufficient in the balance. If the balance amount is greater than or equal to amount or if the amount is less than or equal to balance, from the current balance that amount is being detected. So we are getting a message repose, repose amount debited. What is the balance? This dot balance. So in case if the condition is not true, we are giving an error message to the customer saying that error insufficient balance. So this is what our, I mean, one more method to get the details of the account. If the account is already there, we want to call this function, get balance. It will display the account number, this dot ACNO. It will display the name of the account holder and the balance amount of that account at that time. So three properties and three methods for this account class. Let me save this. Have a look into this. So three properties, two constructors, deposit. What is the logic of deposit? And also we got withdraw method and get account details. Then we want to develop our actual application, a bank app or simply bank. A menu-driven application, create account, deposit, withdraw, details and exit. A menu-driven application to be displayed. So this will come. First we want to create an account. If the account is already available, then only you should allow to deposit the amount, then only withdraw well should happen, then only details should happen and exit. So let me create a separate application. New Java class, bank. Public static word mean. So in this, we'll have a local variable account. ACC is equal to null. To read the data from keyboard, I'm using a scanner. So scanner, SSC reference is equal to new scanner from where? From the keyboard, system.in. We want to read the data from keyboard available in java.util package. To read the data. So continue the process while true, infinite loop. This is what the end of while loop. What is required there? A menu, S out. One, we have create account. Or a new account, any message you can write based on your requirement, create account. The second operation is two deposit. The third one, S out. System control and space bar. Control key and space bar three, withdraw. The fourth one, what is that? The fourth one, details. Account details or balance details, S out. Exit. A menu driven application. After that, we should ask the customer. I mean the bank officer to, so remember this application is a very basic application just to understand class, object, constructors, methods used in a real project, where it is used. And we are not working with multiple accounts also, only one account we are working with. Now, S out. We should ask that officer, the bank officer to enter an option. What the customer wants to do? So, let, I'm not, let inter OPT is equal to ssc.nextint. So, enter an option. An option is being entered. So, once you enter the option, that option may be an A number, it may be one or it may be two or three or four or five or it may be other than that. So, there we can use the switch case. We use switch OPT. The switch means the case may be one, break. Case may be two, so what is case may be one, create account. If the case is two, make a copy of this. What is this case two? If the option entered is deposit, the other one, option three, withdraw. Option four, get the details. We are making a structure of our project. Case five, terminate exit application or terminate application. To terminate application running, to terminate the application, we just give a message s out, bye bye. So, something like that we are just providing bye bye and we want to terminate the program. So, which Java statement is used to terminate the program? We say system.exit, yes system.exit with an exit handler zero. So, this is what the Java statement used for terminating a program, system.exit, the application will be closed. Then if the option may be other than one to five, that we call it as default, we can give a message saying that invalid option, invalid option, trial again. So, let us display the loop once again. This is what the end to switch. We just give a separator. So, the structure of the application is done. So, system.exit, to terminate the application and default case that option what you have entered is not correct, it is not one, two, three or four or five. So, if it is one or two or three or four, what is that you need to do for deposit? Deposit means, now let's see what happens is, run as Java application. A menu is being showed, asking me to enter create account because no operations are given, so nothing is working. Deposit, if I say an option six, it is an invalid option. What is coming? Valid option, try again. If I provide the option five, bye bye and the application is terminated. This is what the structure, now what I need is, when you talk about deposit or withdrawal, deposit or withdrawal or get details should happen only if the account is available. If ACC not equal to null, if the account is available, that means it's not equal to null, what is that we need to do? Enter the customer, ask the customer how much amount you want deposit, enter amount to deposit. So, enter amount to deposit will say, float amount is equal to sse.nextfloat to read the data from keyboard, a floating point value to read, we use scanner.nextfloat, we got the amount. This amount to be passed to account objects deposit method, for that purpose, ACC is the account reference dot deposit by passing that amount. This is what the logic for deposit. If the account is not equal to null, that means account is null, we can give an information to the bank officer for your information, create account first. In a bank account is required, then only he can do any operation. Now, what else we need to do for the second one, withdrawal? What logic to be done for withdrawal? So, withdrawal also, if the account is already available, if it is not equal to null, enter amount to withdrawal, float amount is withdrawal, and you call the method by using ACC. What is ACC? Account reference. So, we will create an object. So, ACC dot withdrawal. For your information, create account first, ACC or UNT, create account first. The same web details, what is that details? There also, if the account is available, if the account is already there, then we will call the deposit method. ACC object is calling get, what is that method we got? What method is to get the details? Get balance method. So, call the get balance method. Get balance method. Call that get balance method. Create account first. So, that's deposit, withdrawal, and getting the balance also we define, five, six also. Now, let's run this. When you run this application, it is asking, create account nothing is done. Deposit, what message we will get now? Create account first. For your information, create account first. We provide the option three, create account first. Four, create account first. Five, terminate the program. All right, so now we are only left out with, to create an account. So, if the user enters an option one, you have to see whether the account is not existing if ACC is equal to equal to null, then only we can create a new account. Else case, we will give a message S out. For your information, account is already created. So, I don't want to change that account. Account is already created. So, if the account is not created in this application, normally in a real banking application, account number will be auto-generated. But in this case, we will enter the account number, system.out.print, enter account number. But in a real application, account number will not be entered. So, account number long ACC or ACNO is equal to ssc.next long. To enter a long value, we will say ssc.next long. So, just imagine we entered a number, a long lengthy account number. Suppose I enter 10025, something we have entered. After that, we will press the enter key. Then next to one, we want is account holder name, system.out.print, enter account holders name. So, string name is equal to ssc.next line to read one line of data from the keyboard. The scanner object is already created. That's connected to system.in. So, we are reading the data, ssc.next long. So, we already know how to read the data from keyboards and all. So, enter account holder from our previous codes. You will get that. So, enter account holders name. We got that. Yes, out. The next one is what? Enter initial deposit. Enter initial deposit. So, how much is the initial deposit? So, that is a float value. Float amount is equal to ssc.next float. So, we have got next to float. We got that all the details. After getting that, create account object. To create account object, already ACC's reference is there. New account by passing the account number. Name of the account holder and the amount. Initial deposit amount. So, we can say yes, out. Account created. Account object is created. So, new account, account number, name as well as amount. So, what happens now? It will go to account class and the constructor will be called. And that account number, what we have passing that is assigned to that object's account number with reference, the name and balance. So, account is created. Now, let's run. So, there is one small issue. Let's see, run as Java application. You see very carefully. I'll give the option one. Enter account number. 10025145 is account number. What happens now? After entering the account number, I give one, I press enter key. When I press the enter key, it will just display this message, but it's not allowing me to enter the name of that account holder. It's asking me to directly enter the name. So, when you press enter key, this function is already executed. So, to take care of this issue, just below this, you just write next line. To take care of that enter key, I just give next line, scanner.nextline. Now, you run this. Understand the first option one. Enter account number 100251023 is account number. When I press enter, this function will take care of that. So, it is asking me to enter the name of the account holder. I'm just entering Sunil Joseph. Initial deposit may be 25,000, rupees or dollars or pound or yen or whatever it is, 25,000. So, what is happened? Account is created. So, the account number is this. Name of the account holder is Sunil Joseph and deposit method. Now, I want to provide an option four. So, when I provide option four, what it will do? It will call the get balance method. Account number, because we have given option is four, case four. Accounts not equal to null, yes, correct. ACC.getbalance, the current object is calling get balance method. Account number in the same line, all the details will be given. So, account number, name of the account holder and the balance amount. Now, I want to deposit some amount, maybe $2,500 or rupees. So, deposit to enter amount to deposit $2,500. So, what should be the message we get? So, enter deposit amount credited. Rupees, so-and-so amount credited, 2,500 credited. Current balance is what? The balance is 27,500. Rupees, 2,500 credited. Balance is this. Whatever the currency symbol you want, you can provide there. So, I'll just provide again to 2,500 again we are depositing, so balance is 30,000. Get the details, four. I want to withdraw $35,000 or rupees. What will happen? Error, insufficient balance. Now, I want to withdraw. So, we will say option four. Now, three, I want to withdraw 30,000. It is sufficient. The account balance will be zero. Now, we are terminating the application. Or if I provide any other option, any other number, invalid option try again and I'll say four details and we will say five, terminate the program. A real application to understand class, object, constructors, methods, all that. Hope you are clear with this one. Happy learning. So, here we are talking about the next one. Important feature of oops is nothing but inheritance. So, what is basically inheritance or why we go for inheritance? Just imagine in our project, in our application if we need to have two or more than two classes which has got some common properties or common functionalities rather than writing the code in each more than the two classes rather than writing the code, we can do the concept of inheritance. So, what is basically inheritance? By using inheritance, what is that we are getting? So, inheritance is a mechanism in which an oops principle in which one object acquires all the properties and behaviors of the parent object. Or we are creating a concept from an already existing concept or concepts. Now, why do we need to go for inheritance concept? What is the importance of that? So, some common properties and methods, what are properties? Member datas or attributes and methods are required by few classes in a project. Hence, they have to be implemented in all those classes. Normally, the common properties are required in multiple classes. You have to write that code, even the functionality also. To avoid code redundancy, duplication of code, a class is developed with the common attributes and methods and it is used as a base class for the derived classes. So, in a project, if two or more than two classes required some common properties and methods, rather than writing in each and every class, we define that in a separate class as a use case. We have a banking project and we know in a bank, one type of account is savings account and savings account have got account number, the basic requirements, account number, name of the account holder, balance amount and rate of interest, maybe 3.5 percentage annually. Then the functionalities are deposit, withdraw, get balance, calculate interest. These are the functionalities of savings account. And the other type of account we have is current account. In a bank, we got current account, that current account have got account number, name, balance and our bank, in a financial year, there will be some limited number of transactions will allow, for example, 12 transactions may be allowed. But apart from that 12, more than 12, if the transaction is happening, the bank will charge some service amount, service charge they will collect. Suppose the default, the minimum, I mean the number of transactions, the free transaction allowed is 12 in a financial year. But if that customer have done maybe 15 transactions, so how much service charge to be calculated to be collected, 15 minus 12. And he will say one dollar or 100 rupees, so that additional transaction, three into 100, that much amount to be collected. So deposit, withdraw, get balance, service charge. So when you see these two classes, in both these two classes, account number, name, balance, deposit, withdraw, get balance are common. So what inheritance says is, don't write that, don't, you should not have code redundant, I mean, duplication of code. So what is the best one? Create a separate class called account. In this class, we define the account number, name and balance, deposit, withdraw, and get balance methods we define. And you create the savings account and current account from the account class. This is what we talk about inheritance. So what is the benefit we are getting? The savings account and current account are the extensions of account. Other than private properties, whatever other than private properties and methods will be inherited to savings account and current account. It's nothing but extensibility. So that no need of having the account number, name, balance, deposit, withdraw, get balance in savings account. The same properties and methods are not required in the current account. Only the additional properties and methods are sufficient in this one. This is what inheritance is. Now what are the different types? What are the keywords used for inheritance? One is extends and the other one is implements. So implements keyword we will discuss in the coming lessons, extents and implements. The class savings account extended from account or current account extended from account. Implements is used with interfaces in the coming lessons we'll talk about that. So savings account, current account. So savings account is an account. So it's nothing but is a relationship. Savings account is a child of account or savings account is an account. Current account is an account. So it's a is a relationship. Exists between two objects. The parent class is called as the superclass. So in object-oriented programs. Some languages we call it as base class and derived class. The newly created class is derived class. In some programming languages, we call it as parent class and subclass. But in Java, the newly created class is called as the child class. And the class from which it is created is superclass. So account is the superclass. Savings account is child class. Current account is child class account. So savings account and current account are child classes of account. The child classes inherit all the members in non-private. If it is private, it is specific to that class only of the parent class. The child class also have their distinctive members. So what are the distinctive members of savings account? It is interest. What method wise? Calculate, I mean calculate interest. Current account, number of transactions, service charge, calculate service charge, whatever it is. So that method is specific distinctive members of the child class. Now what are the different types of inheritance? The different types of inheritance are, one is called as single inheritance. We got class A. From class A, we are creating a new class called B. And when you create an object of B, that object is able to access its own members and also the members of class A. The second one, hierarchical inheritance, class A. From this class A, we are creating multiple child classes, B, C, D, that's what hierarchical. The other one, multi-level A, B, C. B is a child class of class A and class C is a child class of B. When you create an object of C, that object can access its own members, members of C, that of B and that of A. The next one, multiple inheritance or we have got two different classes, class A and B. Each class have got its own properties and methods. And from class A and class B, we create a new class called class C. So as per UPS, not in Java, as per basically object-oriented programming. Class C object can access its own members and also the members of A and B. And we will see is there any issue with this one also. Then the same way, the combination of hierarchical, multi-level and multiple inheritance is what we call it as hybrid inheritance. Class A, from class A to child classes B and C. What is that inheritance? Hierarchical inheritance. From B and C, we create a new inheritance called, I mean, new child class called class B from B and C. What is that? Multiple. And levels are there, level zero and level one, multi-level is happening. So that's what we talk about, multi-level inheritance. I mean, this is what hybrid inheritance. So a combination of all these three. Now let's think about multiple inheritance in detail. So when you see multiple inheritance in detail, let's say I got a class called A, one simple class A. This class have got a method called void display. One simple example, void display. So this void display have got a line of code system.out.println of capital A. We are just displaying capital A. This is class A. The same way, one another class we are having, we are just talking about is there any issue with this multiple inheritance. Class B. This B class contains a method called disk. So this has got a statement, system.out.println. It will display capital B, system.out.println B. All right. So two independent classes. From these two classes, we want to create a new class C and extension of A and B. Class C and extension of A and B. Now if you say C, I'm creating an object of C. C is the class, object type. Object reference is OBJ and the object is new C. Create an object. After that, using that object, we call display method. When you call that display method, normally what happens? It will call the display, it will see. It will see whether that method is directly available here. No. If it is not there, what it will do? It will check it in the parent class. Yes, it is available in class A. So the output will be capital A. Then OBJ.disp. Calling that disk method, not available directly in class C. So it will check it in the superclasses A and B. Disp is available, the output will be B. So the answer is A, B. But just imagine. If this class B contains a method called same method display. A and B, there is no relation at all. So B also contains the same method display. And when you try to access that OBJ.disp. What happens? Directly display is not available in its own class. But display is available in both the parent classes. So now whenever a method is called, it can execute only one method. Now the Java is in a confusion like us. Which display method to be executed? Anyway, both display it cannot execute by default. So which display method should it be executing? Which display method to be executed? So Java will think, do I need to execute display of class A? Or do I need to execute display of class B? So this cannot make a decision. This results in an error. And this type of error is what we call it as. Ambiquity error. So because of a chance of ambiguity error in Java, in the case of inheritance, multiple inheritance, Java will not allow us to create more than one, a class from more than one class is after extents keyword, we can provide only one class. After extents keyword, we can provide only one class name. Why this concept is given? In order to overcome ambiguity error, a class cannot be extended from more than one classes. But then a question comes, does Java supports multiple inheritance? Yes, Java supports multiple inheritance through interfaces. We talk about interfaces in the coming lessons. But if a question comes, does Java supports multiple inheritance? Yes, Java supports multiple inheritance through interfaces. So class, my class, I can make my class implemented from multiple interfaces, inter one and inter two. My class is a class which is implemented from. For inheritance, two keywords are used. One is extents and the other one is implements. So this class is implemented from. This class is implements. I am PLE implemented from inter one and inter two. Or there is interface. An interface can be created from interface, inter three, extents, inter one comma, inter two. What is interface and all? We'll discuss in the coming lessons. So interface, inter three, extended. But in Java, a class can be extended from only one class. This feature is given in order to overcome ambiguity error. Hope you are clear with this one. Happy learning. So inheritance practicals. So let's consider we got a class called a simple class called base class. It has got two properties, A and B. And also it has got a method called display AB. So what that display AB is doing is it will say in base class, the A and B values will be displayed. That means 10, 20 will be displayed. So whenever you create an object of base and we can access AB as well as display AB. But my requirement is we need to have a class that should have three properties. AB with the same value of 10, 20, as well as C maybe 30. And also we need to have a method display ABC. So for that purpose, what we do is already A and B is available, display AB is already there. So what we do is we'll create a child class of base with the name of derived. It has got, so by default, if you say extents base, whatever properties and methods are available in base, is available for the object of derived plus in addition to that, we are providing C is equal to 30 and display ABC. So when you see this class derived, it has got only C is defined. But actually it can access the members of base also. That's the reason why we are able to write AB as well as C. Then we write the main class as a inheritance test one. Main method we are creating an object of derived. So that object can access its own members directly C. And also it can access the members of its superclass which is nothing but base A and B are defined in the base class we can access. And when you say display AB, OBJ is the object of derived. You will see whether that method is available in its own class not there. So if it is not available, it will take it from the base class. That means superclass. So we'll get the output in base class. A will be 10 and B will be 20. And display ABC, that method is directly available in its own class. So we'll get the output in derived class. A will be taken from the base. So 10, 20 and 30, this will be the output. So let's see this practically in our eclipse. So the same program is available. Base derived and inheritance test one. So let us run this program. When we run as a Java application, what output is that we are getting? Line number 21, it gives you 10, 20, 30. OBJ reference of or instance of derived. A value is nothing but 10, B is 20 and C is 30. Display AB in base class A value 10 and B value 20. And then OBJ display ABC in derived class ABC. Same like you can create savings account and extension of account and current account and extension of account. So practical of inheritance. Hope you're clear with this one. Happy learning. So this lesson is about overriding members. So what is overriding members? So it's nothing but a feature. So we have seen that in inheritance, the child class can access the members of the superclass. But if some methods available in the superclass, if you define the same methods in the child class also, because we want to have some additional functionality and that is what we talk about overriding. So for example, in the previous lesson in inheritance, we've seen current account and also savings account are the two type of accounts we have. Both are child classes of account. So account have got deposit. In current account, we need to get the transaction count which is not required for the savings account. So transaction count is nothing but if you perform a deposit or a withdraw operation or get balance method. What we need is the transaction count to be increased. Apart from adding the amount with the existing balance or deducting the amount from the existing balance based on the functionality, we need to add some additional coding also in the current account. So for that purpose, we should define the same methods in the superclass in the child class, whatever the methods are there in the superclass. If you want to add some additional functionality, we need to define in the child class also and that's what we talk about overriding. And this is the way in which we achieve runtime polymorphism. So in the lesson, we will see about polymorphism. As a practical scenario, when you see overriding test, derived OBJ is equal to new derived creating an object. So this is what the two overridden members, all together, the object of derived have got four members, A and B of its own and A and B of the superclass. Now, when you run this, we'll get A value of derived, that is 11, B of, 11, I mean, B of derived 22. At OBJ node display, this statement get executed. So let me run this. So when you run this, 11, 22 in derived class, 11, 22, again, 11, 22. But what I need is, we want to access, so when you create an object of derived and accessing the display, control will come here. From there, we want to access the members A and B of its own class. If you want, you can say this keyword also, this dot A or directly B. And the same way we want to access the members of the super, for that purpose, we use a keyword called super, I'll say super dot A. So it will access A of the super, that means base. The same way super dot B, super dot B, super is a keyword of Java. This acting as a reference of the current object, same way super, super reference. Now what happens when you say OBJ dot display, the control will come to this class display method. In derived class, this dot A, that is 11, B, 22, super dot A, what is the value of super dot A? 10 will be the value, super dot B, 20. And if you want to call, from here, we want to call the display method of the super class. So this child class object should be able to access its own members and also the members of the super class. So for that purpose, we say super dot display. Super dot display. Now we run this, we'll get the output as 11, 22 of this line of code, display method, in derived class, this dot A, 11, B, 22, super dot A value is 10, super dot B, 20, super dot display, it will call the display method of the super class. So because of that we are getting in base class 10, 20. So inside derived class method, if you use super, that refers to base, because base is a super class. And when you see class base, is it a child class? Can you use super keyword inside this display method? When you see this class, there is no extents keyword. But remember, in Java, every class is a child class is a child class of Java dot lang dot object, which is treated as the first class of the Java APIs. Collection of classes, there should be a starting. The starting classes, Java dot lang dot object. So just to show you, I'm just creating a new class called test. I'm just creating a class called test. The eclipse is telling that what is the super class of test, Java dot lang dot object. So every class, a child class of Java dot lang dot object, the reason is Java. So every object have got some common functionalities, like some sort of locking, two string, hash code. So comparing two objects, these are all common methods, which is required for all objects. So rather than defining that common methods in each and every class separately, what Java made a class called as Java dot lang dot object. And they made a rule that every class what you create should be a child class of Java dot lang dot object. So that's why we say the default inheritance in Java is a relationship. The default type of relationship is a relationship. So when you see the command prompt, we use Java P, Java dot lang dot object. So these methods are accessible for all the objects. So I can use in simple words. In this display method also, I can use super keyword and that super refers to what? Java dot lang dot object. And these are all the methods that we are able to access. So this is what we talk about overriding. Hope you are clear with this one. Happy learning.