Learn Object Oriented Programming in 10 minutes (Java)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello if you're having problems with object-oriented programming you have come to the right video my friends because they are probably throwing 15 letter words at you trying to teach you object-oriented programming but you're really just oh they're not very good at teaching these concepts simply so that's my goal today is to teach you object-oriented programming concisely simply in only a few minutes so here we go we're in Eclipse I'm just going to make a new project and I'll call it example 1 and then in here we'll just I'll just call this class example 1 actually you can have a 1 with a main method a class is a blueprint for an object so like how we make a scanner object it has methods and variables that we can use well there's a scanner class somewhere out there that says what that scanner can do so let's make an object say that has a name and then the method and all it does is print out my name we just made an object with a class this class blueprint called example 1 has the attribute name and has the ability to say a name this object in the computer could represent any object in real life like these headphones these headphones are grey so we can make a string color and these headphones could like turn the volume up or down the class is a blueprint for making objects and an object is just like an object in real life all it has is variables and methods so now let's get into some of those 15 20 letter words okay we got polymorphism polymorphism just means that you can have multiple methods with the same name but with like different parameters so we could have a name in here and then print out my name is name or whatever polymorphism means many forms so one method could have many forms but have the same name it could have a string name as a parameter if you have I don't know a 2d array of character variables as parameter it could have 20 parameters if you wanted and still be called same name so that's polymorphism and that's called overloading a method means it's the same name but maybe different parameters or different types of parameters the other type of polymorphism is overriding a method say we have another class here I'll call it example 2 and this has a method in here called say hi and all this does is say honey these methods could do anything but this is just simple if we wanted to bring that say high method into example 1 all I have to do is type extends example 2 now example 1 has say high as well so if we added a main method in here to run our code made an example one object and then did a one dots we can see the name we can see say name the other say name from overloading and we can also see say hi even though say hi isn't in here but since we have extends example 2 it sees it and we can do say hi so if we run this it works but we can change the functionality of that say hi by typing it here now this over rides this so now if we run it it will do nothing because since this is the same amount of parameters zero parameters and it's the same name it takes this one instead of the other one so that's overriding now let's get into like what this extends keyword is so we did this thing up here extends example 2 we brought in say hi and of course you could bring in whatever however many methods or attributes this has this is called inheritance it inherits the methods and variables from the other one so if you see extends it just means there's an inheritance relationship here it inherits the other methods of variables and that's inheritance the bottom one is usually called the subclass and then the one it extends is called the super class inheritance is good for reusability of code so you could have another example and then do extend example two on that one and you have multiple classes that all extend from example two and all have say hi because that's an arrogance that's really it now let's do some encapsulation I'll just set this back to its bare-bones class here let's do this bag of dog treats because any object in the real world you can put into a object-oriented programming language so we can have say the flavor and maybe a method called open bag bag is opened now example one doesn't have say hi anymore because we removed the inheritance relationship with that extends keyword now we can do open bag and also see the flavor but a lot of the times people don't care about the variable and a lot of the times the variable is also private so this private public public public private these are called access modifiers which just change when you make an object which variables and methods you have access to so now if we did eat one Dom you don't see a flavor anymore well we do see flavor but it's red if this was in another class I'll put this in example two for now the main method we don't see flavor because private the reason we could see flavor in this one is because it was in the same file but now how do we set and get the flavor without changing the variable since we can't access it well we just make a method to do that for us and they're called setters and getters so we can set the flavor set flavor if I make a method like this to a new flavor and then all we do is do flavor equals new flavor and then we can get it as well return the string get flavor and return flavor now if we try this out we can set flavor since they're public to beef and then we could print out get flavor now we got beef we're able to set and get the private variable through methods and that's called encapsulation now why would we do this because the variables are usually private and it makes it easier for the user to do with their methods that's encapsulation let's move on to interfaces you've probably heard the word interface and we're probably confused as heck like me we can turn this into an interface if I just change in class to word interface and all interfaces is just a list of variables and methods guys object-oriented programming is just objects with variables and methods variables methods that's it is it an interface is just a list of variables and methods so we can do string flavor again put some keywords in here and say like the flavor doesn't change it's gonna be beef forever and the list of methods is gonna have is open back open back like this we don't need curly braces because we don't need to implement or put code inside the method we're just listing them out an interface is just a list of variables methods so now how do we use the interface just like inheritance used extends to inherit those methods now we're going to use implements example one this has to be an example - we get a red underline because we need to add the unimplemented methods from the interface and we see open back here because open bag was in the list now all we do is implement it here with whatever code you want but I'm just gonna do a print statement I can do e two dots open back and that is interfaces this is useful in the real world because maybe you want a list or blueprints for like a high-level bag of dog treats and you want to make a bunch of smaller bags of dog treats that are a little bit different they can all have implements master dog treat bag and then customize what each of their open bag methods are or how each of them are a little different this gets to abstraction abstraction means that only the details that the user needs to know are there and everything else is hidden so like here the interface is completely abstracted because it doesn't say how open bag is implemented it doesn't show what the code is for open bag and that's really it classes are blueprints for objects objects represent real world objects in the computer using variables and methods methods can have the same name using polymorphism you can bring methods and variables from other classes by inheriting those methods using the extends keyword and you can also take a list of methods and variables and implement those methods using the implements keyword and you can also have access to private variables by making methods to change them and get them called setters and getters and that's called encapsulation so those are the really big object oriented programming terms in Java explained quickly and simply for you if you'd like to share anything else you know about object-oriented programming you can in the comments down below help out some other peers and I hope you enjoyed this video have a great day and I'll see you in the next video [Music]
Info
Channel: Alex Lee
Views: 171,812
Rating: 4.9324436 out of 5
Keywords: learn object oriented programming, learn object oriented programming java, learn java oop, java, object oriented programming, object oriented programming java, object orientedprogramming, java object oriented programming, object oriented programming in java, what is object oriented programming, java object oriented programming tutorial, oop tutorial, java oops concepts, oops concepts, java oop tutorial, object oriented, java objects, object oriented programming tutorial java
Id: CWYv7xlKydw
Channel Id: undefined
Length: 10min 5sec (605 seconds)
Published: Mon Nov 11 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.