Transcript for:
ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग परिचय

so from today onwards we are going to start object oriented programming Concepts object oriented programming so at the beginning session I've shown you like what is an objectoriented programming language if any language supports uh objectoriented programming Concepts we can call it as a objectoriented programming language so what are those Concepts there are mainly six concepts are there we call it as a objectoriented programming Concepts so what are those Concepts the first concept is a class and then object then polymorphism encapsulation inheritance data abstraction so these are all called objectoriented programming Concepts if any language supports all those features we call it as a object oriented programming language object oriented programming languages but some languages doesn't support any of these Concepts and some language will support only class and object doesn't support any other things but Java is supported all the concepts so it is purely objectoriented programming language okay so as part of today's session first let us try to understand what is class and object so these are the two fundamental entities which we need to understand first and once you understand class and object then only we will able to understand the rest of the concepts because these are the first basic concepts which we have to understand from object oriented programming Concepts these are the foundation these are the base for all other Concepts so today we will focus more on class and object and also I will discuss something about methods class contains methods okay so what is the first class what is a class general definition a class is collection of attribute and behavior this is a simple definition of the class class is a collection of attributes and behavior class is a collection of attributes and behavior simple meaning is a category or a group we call it as a class for example uh let's say I'm taking some example here let's say animal animal so animal is just a a name which we have given to particular group right but there is that's not physical but what are the physical entities here is dog is a physical elephant is a physical horse is a physical these are all physical but all of them comes under what one group that is animal so that is called class and the class is a collection of attributes and behavior that means these animals are having a similar type of attribute similar type of behavior so we call them as one group one category that is called class simple okay for example let's take another one and there are some people there are some students are studying in the class let's say every student let's say Kim David Scot these are student students they're studying in a class and every student is having their IDs every student is having their name grade and so on but all are comes under what student category student is a class and these are all called objects and animal is a class and these are all called objects of animal these are all our objects of student class okay for example let's take an organization in organization there are so many employees are working and uh if I look at here every employee is having their own data like employee ID employee name salary all these things and John Smith Mary so these are all different employees working in an organization but they are all belongs to one group or one category that is employee so employee is a class and these are all objects of employee class so simply what is class class is a collection of attributes and Behavior attributes in the sense what every animal is having their own attribute means color height okay they're all attributes Behavior means the way of eating the way of running the way of sleeping all these comes under Behavior so these are all comes under one category animal these are all comes under one category student so these are all comes under one category which is employee so if I look at here an animal student employee these are all classes category name but they are not physical so there is no physical existence of animal student or they are just a name we have given to the particular group based upon attributes and behavior right similarly student is just a name we have given to the particular group of people employee is just a name we have given to particular group of people particular group of people who are working in company but they are not exactly physical they're not physical but whatever comes under that particular group they are physical right these are physical every physical entity is having their own attributes and behavior but the attributes can be different Behavior can be different but almost a similar type of attribute similar type of behavior they will have So based on this understanding we will know exactly what is class class is just a virtual entity there is no physical entity so this is simple virtual entity there's no uh this is not a physical entity it's just a name which we have given to particular group that's it that's go class okay in other words we can simply understand it is a blueprint is a class is a plan or it's a blueprint it's a blueprint what does that mean for example let's say before uh constructing an house so we will have one plan right so we will have one structural plan so based on that plan we can construct house for example let's say let's say there is a plan like this and based on this blueprint or plan we can construct real houses we can construct n number of real houses and what is this plan is just a blueprint but based on this plan based on the blueprint we can construct multiple houses so these are all different objects of one single class this is a class so in other words we can say a class is a blueprint a class is a plan or it's a blueprint based on that we can construct multiple houses same thing based on the class we can create multiple objects so one class can have multiple objects we have one class we can create multiple objects we have okay so the class is what a physical entity sorry class is a logical entity it is just a name which you have given to the group of elements or group of objects in other words we can say the group of objects are called as a Class A group of objects also called as a Class A Class is a virtual entity whereas objects are physical entities objects derived from the class without class there is no object so without class there is no object so all objects are derived from the class and one class can have multiple objects this is the connection between class and object okay class is a category it's just a name which we have given to the group and whatever is there in that group they all comes under objects and they are physical in nature okay so let me put all the definition here so we will try to understand both what is class what is an object and what is a difference so how can we define object object is an instance of Class A Class an object is an instance of a class now let us discuss the differences between class and object first class the first point as I said before class is a collection of attributes and behavior this is a generic definition generic definition in the sense commonly apply in everywhere class is a collection of attributes and behavior so in Java perspective attributes are called variables behavior is called Methods okay attributes in the sense variables Behavior means what methods in Java so as per Java the class is class is collection of class is a collection of variables and methods what does it mean when I create a new class in Java which contains what just V variables and methods so we can create a multiple variables we can create a multiple methods we can create a single variable we can create a single method so basically the class is a collection of variables and methods the class contains the variables and methods nothing else that is a definition so when you create a class we should have some variables and we should have some methods now the second poin class is logical entity so logical entity means what logical entity or is a blueprint means it is a virtual it is not a visible it is a virtual means it is a not visible it is a virtual that's the reason is a logical entity so whenever say it is a virtual logical entity invisible obviously it will not occupy any space in the memory right so it is not a physical whenever it is a physical then only it will occupy certain amount of space in the memory if it is not a physical it cannot uh occupy any space in the memory so class is a logical or entity it's not physical entity it's a logical entity so it will not occupy not occupy space in the memory it will not occupy any space in the memory so these are the three important points which we have to remember class is a collection of variables and methods when you create create a class which should have some variables and methods it is a just a logical entity or blueprint means it is not a physical entity is a purely logical entity and uh so it is not occupying any space in the memory because it is a not physical so how to create a class in Java by using class keyword we have to create by using class keyword this is a syntax class and space we have to provide some name of the class let's say my class name is what employee so after creating this class Open Bracket and close bracket inside this block we can create variables and methods what is this class contains multiple variables we can create multiple methods also we can create I will explain what is Method later but now just follow this one okay class employee which contains the variables and which contains the methods so for we are writing main method right so the main is also one of the method so along with the main method we can also create multiple methods so basically the class contains the variables and also class contains the methods this is a syntax how to create a class right now what is an object so we have understood what is a class class is a collection of variables and methods it is a logical entity or blueprint it not occupy any space in the memory why it is not occupying space because it's a just logical there's no physical right so object purely logical entity so it will not occupy any space in the memory so this is a syntax how to create a new class now come to the object so what is an object so we can create an object only if we have a class okay so without Cate creation of class we cannot create an object directly because the object is derived from the class itself so we can say an object is object is an instance of a class okay and other words we can say object will be created by using a class okay object will be created by using class so first we have to create a class then we can create an object of this class so objects are always derived from the class we can create n number of objects for one class so object is an instance of a class and one more thing is object is a physical entity object is a physical entity object is physical entity so class is a logical entity by using a class we can create an objects so objects are physical so whenever I say objects are physical definitely they will occupy certain amount of memory so occupy memory okay or can say occupy space in a memory so definitely because these are the physical definitely they'll occupy certain amount of space in the memory and one more thing is we can create n number of objects for single create single class we can create multiple objects mult multiple objects for single class so this is all about object but how to create an object for the class if you want to create object for the class we have to take the class name and where then variable name employee let's say so normally how to create an object by using new keyword we have to create an object so new then class name employee and then bracket so this will create an object actually new employee this is this simple statement will create an object so but once you created this object how can we refer that object we need some variable so as soon as you say new employee this will create a new object and how we can refer this object we need some variable we need some variable so that variable we can create so how to create that variable is just specifying the some variable it's a EMP equal to now what is the type of this variable OB viously it is a employee type of variable because the class name is employee so the variable also should be employee type so then only this will able to hold the object of employee okay so this is a syntax of creating an object class name variable name equal to new this is basically called as Constructor in the next session I will explain what is Constructor so this is a class name followed by bracket so this is is a syntax of creating an object you can create any number of objects let's say emp1 is one object now I want to create another object you can say employee emp2 emp2 equal to new employee similarly I can create another object employee 3 equal to new employee so like this you can create a number of objects for single class for single class we can create a number of objects okay so object is an instance of a class or object will be created by using a class and it is a physical entity it is will not it will occupy certain amount of space in the memory because it is an object we can create n number of objects for single class but when you create an object what will happen what is the use of an object why we need to create an object for the class so let us try to understand this concept for example uh we created some class let's say this is my employee class okay this is my employ class so what is class contains class contains variables and methods as per the definition class contains variables and methods so let us create some variables here let's say integer employee ID integer employee name integer employee salary like this I can create multiple variables now apart from this variable I will also create one method which will display employee data okay which will when I call this display method this will print employee data all the details so this is a class creation so once you created a class we can create multiple objects so let's create one object here let's say emp1 and another object EMP M2 another object emp3 like this we can create any number of objects but when I create an object what is the use of this object so whenever you create an object the object will acquire their own copy of variables and methods from the class that means the class contains these three variables and Method right so even emp1 object is also having same variable EMP ID eame and salary and then display method same emp2 also acquire their own copy of variables and methods here also EMP ID EMP name salary and then display method same emp3 also acquire their own copy of variables and Method again EMP ID EMP name EMP salary and then display method so whenever you create a object that will acquire their own copy of variables and methods from the class itself okay and we cannot directly work with the class variables and methods only through object we can access all the variables and methods so once you created first step we have to create a class second step we create an objects and once you created an object the object will acquire their own copy of variables and methods from the class itself it is derived from the class itself class is a base for the object okay once you created an object the values of variable can be different right variables are same for every object but employee ID of emp1 can be different of employee IDE of emp2 employee IDE of emp3 right every employee won't have same EMP ID right the data can be different so here employee ID can be 101 here employee ID can be 102 here employee ID can be 103 that means every object is representing one employee like that so similarly employee name can be different here x y and here it is J employee name can be different maybe sometimes the values can be same no problem but every object is independent there's no connection between these objects even though they have derived from the same class listen this very very carefully most important once you created your class you can create multiple objects based on the class and every object object will acquire their own copy of variables and methods from the class even though they have derived from the same class they are independent there is no connection between these objects emp1 is different EMP data and methods are different emp2 data and methods are different emp3 data and methods are different and they created based on the same class but they are independent why they are independent because this object will occupy different space in the memory somewhere else it will store this object will store somewhere else because these are physical physical means they will occupy certain amount of space in the memory so this object will store somewhere else so there is no connection between these objects all are different even though they have created from the same class so what is an object contains object contains the variables and methods and we don't initiate the data in the class suppose if you put employee ID 101 in the class itself then what will happen when you create an object every object employee ID becomes one1 it doesn't make any sense right so if when you put the data directly in the variable in the class itself if you specify the data then what happens when you create an object objects also will acire the variables right so when I acquire the variables the data will be same one 1 1 0 1 01 so it will be the same that is a reason most of the times we don't assign data to the variables in the class just we create a variables and Method and once we created a object inside the object we can change the values we can add values to the variables and we can implement this method also so the variable values can be different from one object to another object the method implementation also can be different from one object to another object but they are created based upon same class class and class is a logical entity whereas objects are physical entities now we will directly work with the objects not with the class we will just create a class but we won't directly work with the class once you created an object we will work on this objects because they are physical we will operate objects we will do calculations based on objects not based on the class okay so how to access this variables and how to access this method only through object emp1 doid emp1 name emp1 doel emp1 display like this we will able to access similarly if we able to access the variables and Method from the emp2 object we say emp2 EMP ID emp2 do eame emp2 do salary emp2 do display like this so by using dot we will able to access everything from the object similarly if you want to access everything from EMP three object you can say emp3 emp3 name emp3 do salary emp3 do display like this we can access so by using this object reference variable we can access everything from this objects objects are independent we will operate these objects differently because they will store in different places in the memory okay so this is basic understanding what is a class what is an object so for everything is clear theoretical understanding first we need to have theoretical understanding then I will show you practical implementation first how to create a class I will show you how to create a variables and method that we will see once you create a class we will try to create multiple objects once you created an object we will see how can pass the data to the variables and how can we call this method how to operate this objects okay everything I'll show you practically first we need to have some theoretical understanding what is a class what is an object what is the difference between in class and object okay this is a fundamental the basic stuff for all other objectoriented programming Concepts now let us move to the Practical implementation so go back to eclipse and create new package for today day 10 okay so inside this first step I will create a new new class directly take a new class uh no we should not say class is a parent so the meaning will change actually so parent and child relationship is totally different in inheritance we will discuss that part but we should not say class is a parent of all objects we can say uh objects are derived from the class objects are instance of a class or we can say a class is a group of objects that's the right definition class is a group of objects or object is an instance of a class that's not parent and child relationship actually okay so now let us create one simple class I'll name it as employee okay employee class I'm Crea and one more thing sometimes we will have main method in the class sometimes you may not have main method we can also create a classes without main method okay I will show you all the combinations first of all let me take main method as usual so main method should be there if you want to run the class so this is a main method so far we are using this main method every time whenever you create a class by default the main method should be there so let us keep this main method we will try to use this later I'm not using this main method for now what we have understood here is a class is a collection of variables and methods right class is a collection of variables and Method so we created one class and also we have one default method that is main method apart from this main method I will also try to create some more variables some more methods some other variables some other methods I will this is one method so let's keep this one side now I will create some variables here so inter okay so this is employee class so I can store employee type of data so how to create a variables int employee ID I'm not assigning the data just create a variable we don't normally assign the data in the class okay because if you assign the data here the values will be the same for every object so it should not happen like this then I'll take one more variable to store employee name I can say EMP name e name and I can take another variable called job and I'll take another variable called salary so four variables I have declared for every employees having employee ID name job and salary but the values can be different one employ to another employee the values can be different one object to another object the value can be different but the variables are same right every employee object is having employee ID every employee is having name every employee is having job every employee having salary these These are called attributes basically so these are almost same but the values of variables or the values of attributes can be different from one object to another object that is the reason we will assign the data only through object not directly in the class okay so these are the variables which we have created so as per the definition class contains the variables and methods so I just created some variables now let us create some methods so main is a one method this is also method similarly we will create some more methods so in the next class I will give you detailed information about method what is Method how to create how to pass parameter how to return return the uh result from the methods so we will discuss in detail the methods itself will take one session but here just try to understand with it very high level so I'm going to create one more additional method along with the main method let's say the method name is display no parameters empty bracket means no parameters and here I will just type to print the values of this variable that means just I want to print the data of employee employee data I want to print so I can simply say one print statement here I'm going to print Eid and similarly I will try to print uh e name and then I will try to print this is user defined method we are creating our own method okay we are creating the our own method yesterday what we discuss string Methods they are already created we are just calling those methods but here we are creating our own method okay job and then what else Sal so salary so now I have created one more method here display the method name is display you can provide any name to Method name is user defend you can provide any name and this is called normal method and whenever you create a method you have to specify something called written type sometimes method May return some value or may not return value return means it's a output when you call this method it will return some value sometimes it may not return any value okay let me give you one example yesterday we have seen uh last classes we have seen some string related methods right so for example if I take an string like this welcome I want to find length of a string how to find length of a string yes dot I'm calling length method like this when you call this method it is returning length of a string so that return returned value we are storing into some other variable or we are directly printing the length so when I call this method it is returning some value this is output it will return similarly sometimes method returns some value sometimes it may not return any value sometimes it may not return so if a method written a value we have to specify what type of value it is rning suppose if is a returning integer before this method we have to specify integer if this method is returning string we have to specify return type as a string if this method is rning nothing we simply say void okay sometimes it may not return anything it is just print the output that's it it is not rning any output for us in those cases we can simply say void is a written type and empty bracket is representing there are no parameters when you call this method you don't need to pass any input to this method so no input no output from this method it just print something on the console window that's it so for now just understand only this much next session I will explain in detail about methods okay so don't ask anything about this for now you can't understand so in the next session I will I will make you understand better okay void is nothing but a no return value that's a meaning of void if I don't space specify written type it will give you an error as per Java whenever you create a method you have to specify the written type okay return return type you have to specify so if you if the method is not returning anything for example then you have to at least specify void void means nothing no written value okay that is a representation so we have to specify the void keyword why we are not declaring variables and methods inside the main method inside the main method we should not specify the methods a method doesn't have any another method we cannot create method inside another method we can just create a variables inside this method I'll show you that hold on still we have not completed so try to have a basic understanding I'll answer all the questions but it should be step by step otherwise you will be confused this is a little complicated concept especially for beginners definitely they will confus so try to understand step by step so don't directly jump into the complex things I will make you understand everything just to follow me so we created some variables in the class along with the variables I created one method and main method is also there so how many methods are there in the class now as of now how many methods are there in the class currently two methods one is a display method other one is main method so if you look at this there is a difference in this if I look at here display is the name of the method here main is the name of the method here it is not taking any parameters but this main method is taking some parameters and here this display method not rning any value same thing main method is also not rning any value but in addition we have a public and static these are called access modifier public is an access modifier static is having a different meaning but this method is not a public not a static method so these keywords are not mandatory to specify but the return type you must specify for the method so I have just created the normal method it's not a static method not a public method it's just a normal method okay so display is one method main is another methods now currently this employee class is having variables and methods so always we have to treat main method different is a special type of a method we should not compare main method with the normal methods why because if you create a main method then only you can execute this class if you don't have a main method you cannot execute this class execution is always start from the main method Java is always look for the main method in the class before execution so that is the reason you have to create a main method in the class if you want to execute this class if you create a normal method you cannot execute the class main method should be there and not only that whenever you create an objects for this class the objects should be created within the main method we cannot create an object anywhere else only in the main method wherever you're starting execution there itself we can create multiple objects so objects can be also created only in the main method and remember this the hierarchy is most important the class contains what variables and methods variables and methods what is Method contains what is Method contains inside the method we can access the class variables or we can create our own variables inside the method but method should not have another method we cannot write like this okay for example when I create one display method like this this is the one method inside this method I cannot create another method like this again create one void okay void print like this we cannot create another method within the method so this is another method we cannot do like this okay one method should not have another method only method contains the variables that's it that is a reason if you look at here the class contains the variables the class contains the two methods and this display method we should not write in the main method okay why because the method should not have another method methods are different but class contains a multiple methods so class contains a display method class contains a main method but this display method should not write in the main method got my point and you can create variables in the method so these are class variables and if you create some variables inside this display method we can call them as a local variables those variables we can access only in the display method similarly we can create some variables in the main method also and and those variables are local to main method but whatever variables we created here these are the class variables means we can access these variables everywhere in in every method we can access okay that is the difference now when you create a class contains the variables and methods now what is the next step we created a new class okay once you created a class what is the next step objects we have to create right when you create a class only class there is no use until unless we create an object until unless we create an object there is no use of class just is a blueprint so now we created a class this is our class employee class for this class we have to create multiple objects and we will operate we will do operations on these objects we will operate these objects we will work with these objects not with the class but when you create an object before that we have to create a class so now we created an employee class which contains some variables which contains some methods but now we have to create an objects and how to create an object where we have to create an object so every time we have to create an object only within the main method remember this point okay objects can be created only within the main method we cannot create anywhere else we cannot create an objects inside the normal method so if you want to create an object object of employee those objects should be part of main method this is the thumb rule okay now let's come back to the main method now how to create an object for the employee class so employee emp1 equal to new employee this is how we need to create an object this is a object okay so now once you created emp1 object for the class then what will happen so this is our employee class and for this class we created one object called emp1 then what will happen so whatever variables we created here whatever methods we created main method forget about okay main method is not applicable whatever variables and methods we created in a class same variables or methods are also will be there in the one object because this is just a physical physical form of employee so this employee one is also having same variables emp1 is having same methods okay now emp1 is an object we created what is this emp1 is having now emp1 is having the variables and methods which we are created from the class right so it is getting their own copy they're getting their own copy of variables and methods so now the emp1 one object is having variables and methods so what are the variables the emp1 is having now employee ID is one variable employee name is another variable job is another variable salary is another variable and what are the methods emp1 is having what are the methods emp1 is having display method so main method we should not consider because there's a main method execution start from there everywhere so now the currently mp1 object is having four variable and one method okay now we will try to operate EMP one object so what we can do now is by taking this emp1 we can assign the data to the variables currently these are just the variables there is no data in the variables right so now we need to assign some data to the variables how to assign the data to the variables emp1 dot see here you're able to get all the variables here automatically populated so let's take EMP ID so employee 1 EMP ID is 101 similarly emp1 do eame John I can assign data the object level emp1 do job manager then emp1 do salary some value so like this we can assign the data into the variable of that particular object now this is all about data of emp1 object okay now we assign some data to the variables now if you want to print the data I want to know the details of employee one then what we can do we can simply call the display method so display method is already implemented as part of the class right we are able to print all the data so the same display method is present inside this object same display method is present inside the emp1 object so once you assign the data now when you call this emp1 do display then what happens this particular method will print the data of emp1 object okay now when I execute this observe very carefully when I execute this this will print the data of EMP one object so who is printing this data the display method is printing the data so before calling the display method what we have done we have assigned the data to the objects we have accessed all the variables from the object and we have ass send some data to the variables then we call display method so it is got displayed the data so this is how we can create a new class class contains the variables and methods and once you created an object of the employee class through the object we can access all the variables and assign the data and then we can print the data of emp1 object similarly let me create another object so now I'm going to create another object of same employee class emp2 new employee this is another object for the same class it is another object employee emp2 equal to new employee and at the time of creating an object you should not use same names here emp1 should not be repeated here mp1 should not be repeated here guys is my voice clear everyone okay so this is the second object okay once you create a second object what will happen it will create another object so two objects we have an employee class for this employee class first we created emp1 object and we have assigned the data we call that method this is over now I'm going to create another another object emp2 so when you create an emp2 object then what happens it is also acquire their own copy of variables and Method from the EMP class so whatever variables we created employ class emp2 is also having their own variables Eid eame salary job and then display method so now we want to assign the data in the emp2 object so how to assign the data into the emp2 object how to access the variables from the emp2 object how to access by using dot so emp2 do e So currently it doesn't have any value we need to assign some data so one2 emp2 dot eame eame okay and then emp2 dot job then emp2 dot cell cell then we have assign some data now so once we assign the data what is the next thing we should able to print the data of emp2 how to print the data of emp2 we just call display method from emp2 object so emp2 do display so this will print data of emp2 so now when I execute this run as Java application see this is a data of emp1 this is the data of emp2 okay so this is how we can create object and we can assign the data in the object variables we can call the method from the object so like this you can create n number of objects for the same class so now you got some basic idea about the class and object everyone please confirm in the chat window okay suppose if you don't have this display method okay so I have assigned some data to the variables but I don't have this display method for example I have not created this display method in the class so obviously objects also doesn't have the display method objects are having only variables so I have assigned some data to the variables then if you want to print the data of the variables without a display method is it possible or not yes it is possible so how it is possible we directly print here instead of calling the display method here we have to write a print statement system print so we we have assigned some data to the EMP 1. Eid now if you want to print it what you can do you can just put that variable directly here emp1 similarly I can write multiple print statements to print multiple variables EMP do emp1 emp1 name emp1 job emp1 do salary you can write multiple print statements okay you can while adding the data or while assigning the data you can access the variables by using object similarly at the time of printing also we can access the variables by using object if you do not have a display method that is the reason instead of writing multiple print statements for every object we just cre one user defined method and just we call that particular method this will print all the data from that particular object okay so without this display method also we can access the variables but we have to use we have to create our own print States okay so that's not recommended so this always try to create one user defin method because that's a common for across multiple objects right so now you got guys understood what is a class what is an object how to create a class how to create an object and once you created an object how to access the variables and how to call that method from that object so this is a basic fundamental understanding okay and remember one thing objects are different so emp1 object is different emp2 is different so if you want to access the data from emp1 object we have to use emp1 dot if you want to access emp2 data we have to use EMP to dot okay both are totally different type of objects type is same objects are der from the same class but physically they are different okay so now let me tell you something else so we created one class class contains a variables and variables and also methods so sometimes we should not create main method in the same class we will create a separate class where we will maintain the main method okay so without creating main method also we can create a class without having main method also we can create a class plain class but which we cannot execute but we can reuse the class in multiple places so let me tell you scenario here without main method if I create a class why we need to create so normally in the real time uh what will happen is if I look at real time projects normally uh there are n number of modules main modules sub modules that divide entire project into different modules so every module is having different classes you can create n number of classes or n number of modules in your project but the entire this is all one single project for one single project always we will have only one main class which contains a main method okay and from this we will operate all the classes so these are all just the plain classes which are having variables and normal methods so wherever we create a main class wherever you have a main method that is called main class whichever class includes this main method that is a main class so if you want to run this whole project we will start from this main class in this main class we will create an objects of all all these classes and all these objects we will all these classes we will control from Main class every class we should not have main method in the real scenario every class we should not create main method so for entire project there will be one single class contains a main method and rest of all classes are just a plain classes they don't have a main methods because we don't run run individual classes we will run the whole project as one single entity so execution should start from one single place that is main class why we are calling main class because this class only contains a main method and from this main method we will operate all other classes so always we will create one main class contains a main method and all other classes objects we will create inside the main method that means normal classes will be different and Main class will be different the main class contains the main method only one single main method we should maintain throughout entire project but how to operate these classes from this main method we will create we will able to access all the classes because all of them belongs to same project so we will able to access all the classes we are able to create an objects in the main class then we will able to operate so the main method we separate in another class and all other classes are one side main class is another side the main class contains a main method but currently what we have done in our current example is we have included the main method also in the same class so in the same class along with the variables and Method we also included a main method so that we are able to execute this class directly if I run as Java application we are able to execute the main class main employee class but normally in the real scenario we don't put main method for every class there will be only one class which contains the main method so now I'll show you if you separate this main method in another class another main class then how can we operate see this let us assume I commented this I will comment this main class sry main method in this class so now assume you don't have have anything you don't have a main method in this class it is just having variables and just having one method that's it it doesn't have a main method I just commented can you run this class now no you will not get the Run option here okay because the main method is not present in this this is just a plain class now if you want to use this class if you want to operate this class we will operate from the actual main class okay what I'm doing is let's say this is a plain class now okay employee is a main normal class now I will create my main class here I will create a main method inside this main method I will create an objects of employee class and then I will operate here similarly tomorrow if you create another class called student and this class also I can create an object here and then I can operate student okay similarly you can create n number of classes and for all those classes you can create an objects in the main method and you can operate those classes but main method should be only one for entire project so same thing I'm trying to simulate here so I have one method called employee this is normal class not a main not a main class why because I have just disable this main method commented this main method it doesn't have a main method now I have some variables and some method so how to create a main class so let's go and create another class I will name it as employee Main and this class should have a main method okay so I'm just taking main method and say finish okay just observe this is the normal class and this is a main class the normal class contains variables and Method and Main class contains the main method so main class always having only one single main method nothing else because objects will be organized only only through main method from the main class okay so now employee class is there already class is present now can we create an object here yes we can easily create just try to copy the same code here that's it see we are able to create an object for employe class we able to assign the data and printing the data same thing we are creating another object assigning the data and printing the data so this task we can do in a separ so main method is created in the same class in the first example now I have separated main method in separate class another class now which class we can run it which class we can run employee or employee main which one we have to run which one we have to execute employee main class we can execute because in employee main only we are able to create an object of the employee class and we are able to operate now when you run this employee main class you will get the result like this got my point so you can create a main method in the same class or you can create a main method in another class where exactly you can create objects and you can operate so this is a approach we normally follow in our real time projects we don't write main method in every class okay and one more thing so in the employee main class we are able to access another class right how how it is possible currently they are in same package the day one means same folder so we are able to access this employee we able to access here but suppose sometimes these two classes are present in two different packages so employee is there in some other package employee main is there in some other package then is it possible to access yes still it is able to access the only thing is you have to import that particular package so you have to write some import statement import and in which package this class is present suppose employee is present in some other package not in day 10 okay some other package then you have to specify that package name okay that package name you have to specify dot even class name also you have to specify class name also you have to specify the same problem so if you're going to access these classes from external package other than same package then you have to write this import statement separately okay otherwise if both are belongs to same package then this statement is not needed import is not required until unless all the files are belongs to same project you are able to access from anywhere from any package you can access okay so this is a simple example we can create main method in the same class we can separate main method in another class and this is the approach most of the times we follow so we can create any number of classes in our project but all the classes we will control or we will organize from one main class and which should contains a main method so now you understood everyone please confirm in the chat window everyone is understood so far how to create a class how to create an objects and main method is there in the same class and we have separated main method in another class I will show you another example so this is one example same thing we will I'll show you another example okay fine so now let us see one more example we just understood some basic concept there are so many things are there still okay it takes two to three sessions to understand the complete whole picture so we will go step by step so now I'm going to create another class I'll name it as a student class I'm not taking main method this is simple just a class student class now in this what is a class contains if all classes are under same project so we don't have to import uh the class right I'm not talking about project I'm talking about packages see guys you need to understand the project structure see the high level entity is what project this is the one this is the project okay the project contains a multiple packages pack one pack two pack three and then every package contains a multiple classes this is hierarchy okay this is every package contains a classes so these classes are belongs to same package so you can access here internally you can access everything one class another class suppose in this class I want to access this one so in this pack two class I want to access pack one class then here you have to import import pack 1. C1 you have to specify the statement inside this class then only can access this external class from back one into back two here the import statement work and all packages inside the packages classes everything belongs to one single project same project okay but when import is required if you're trying to access the class from a different package not different project okay I'm talking about package levels not project level all packages are belongs to same project but when you have to import if you're trying to access class from another package okay then import is required have I understood this see pack one contains a C1 pack two contains a C2 now I want to access C1 into C2 now what we need to do in the C2 we have to specify import okay but C1 is present in the same pack too then you don't need to import okay you don't need to import because C1 is also part of P pack two but if the C1 is part of pack one if you're trying to use in pack two then you have to import pack 1. C1 into C2 anyway we will have a separate session for this packages concept then you will get more clarity on this okay access modifiers packages we have a separate concept for this so do the share do they share classes or methods between projects no projects are independent you don't plub the multiple projects into single project is totally different you should not combine okay so within the project you can do whatever you want because you always work on one single project at a time you don't want assign multiple projects in real time right you don't work multiple projects at the same time one project you will be assign and within the project you will have the full-fledged access you can do whatever you want right so let me show you one more example for class and object so here I'm creating one new class called student and what is a class contains class contains the variables and methods now I'm going to create some variables and methods in this class so to store student ID I'm creating one variable S ID and to store name I creating one more method string yes name and I create one more method care to store grade of a student I create one more variable so three VAR Ables I created S ID s name and grade now to print this values I can create another method called void print the name of the method is user defined you can give any name to this method I can say print data okay and return type is wide because this method won't written anything it just print the data now I want to print the data of the student can we write one single statement to print all this data instead of writing multiple print statements for multiple variables it's very difficult thing right so we can write single statement yes so let me write single statement first I'm printing S ID okay so after Sid uh I'll give some space concatenate with some space and again concatenate with s name again concatenate it with some space and then concatenate with grade so like this we can write one single statement to print all the student data now this is my class which contains three variables one method okay now I'll create another class main student class create a new class I will name it as student Main and here we should take a main method so if you want to see both the windows at the same time you can put the curs you can just click on this uh Tab and drag it down okay you will two windows multiple windows okay so just observe this so inheritance still we haven't discussed don't go beyond the concept please okay next sessions I will talk about inheritance and so just stick to the concept currently which we are discussing don't go beyond that all right so this is your student class and this is our student main class so can we access the student class directly in the main method can we create an objects of the student class yes or no yes we can create now let us try to create student stu1 equal to new student so now one I created one object of student class SD okay now I want to assign the data to this object how to assign the data how to access the student data now whenever I say stu1 which is got created one new object so student is a class for this class we created one object called student one and this class contains what S ID s name grade along with there is a print data so now we have these things in the student one how to access these things by using student one do Sid student one. grade student one. print data so let us try to access it so St 1 do Sid equal to 101 S1 dot s name let some name SMI ST1 dot what else grade is a character type so we should put in single quotations grade is a so now I have filled data into the variables now I want to print the data of the student one how to print stu1 dot print data and just call that method so this particular method will print the data of student one let's try to execute main class so you will see the data here okay so similarly can we create another object yes we can create another object this is one object let's copy this and another object so let's call it as a student two now this is a student two of Sid student two of s student two of grade student and can we have some common data between multiple objects suppose uh here student uh student one name is p can you have same name here yes we can have no problem because there is a possibility right so both the students have same name possibility is there so we can also have same data no problem because until unless the objects are different they are physically different so we can have common data also sometimes no problem okay so I can make it as a one2 in of Smith you can say on radi is a and then print data so now I create another object student two then I'm trying to print the data so this is a data of student one this is the data of the student two so like this we can create class and we can create objects in another main class okay so if you want to see what are all variables you create in the class through the object the only way is you can simply say like this St do1 so when I said dot here it will pop up automatically it will show you all the variables so whichever variable you want you can access it okay so this is a way we can operate classes and objects is it possible to set some data to be unique yes it is possible as it is possible and uh if there is a common data between multiple objects sometimes instead of assigning the data in multiple objects it will be duplicated right suppose let us assume the name is same for every student so every object we have to go and assign the instead of doing it you can directly assign the data here okay s name equal to for example same is name is same for both objects then here you can directly assign Smith okay in that case you no need to assign here here you don't need to assign the name so then what happens this value will be the same for all the objects in tomorrow whatever objects you created for the student class for all the objects the name is same s name is same when you assign the data here okay just observe when I run it as a Java application see the name is same for both objects I have not assigned the data here at the object level commented the statement but still we are getting Smith how it is getting like this because at the class level itself we have directly assign the data so once you assign the data in the class level that is common across all the objects okay understood so if any data is a unique for multiple objects you can specify that in the class directly you can specify that in the class this is one approach but there is another approach suppose I have 10 objects only three to four objects the data is same but rest of them are not same in that case what you will do you have to assign the data only through object you should not specify data in the class this is not recommended actually so this is not recommended this is not recommended when it is recommended if all the objects having same data in future you don't have a plan to change any data for example example if I have create 100 100 for example let's take employee class in employee class let us say have suppose DB number department number yeah school name for example yes so school name is same in those cases you can directly assign the school name at the class level that's it you no need to add the data for every object okay so like this you can uh operate if there is any common data across multiple objects every time that is same all objects the data is belongs then you can directly create another variable assign the data directly into the class itself so in those cases we don't need to assign the data at the object level so that value will be the same for all objects okay everyone understood please put in the chat window so this is a concept of class and object basic concepts still it is not completed actually I don't want to go beyond this for today you will be confused so just practice this this much for today and be familiar with this okay and from the next class I will introduce you multiple things we will see so many other things are missing here okay I will try to explain them in the next one or two sessions this is the first basic things you need to practice first and once you understand this then I can go beyond that because the next all the topics whatever we are going to discuss it depends on this if you not understood this you can't understand the further concept so I will give enough time to understand these things do practice and the rest of the things we will continue in the next sessions okay fine so I will stop here for today's session if you have any questions on this you guys can ask me