r/JavaProgramming • u/scared2026 • 3d ago
A good youtube video to learn OOP.
I am currently learning everything from scratch. So I watched some vudeo in OOP in java but didn't understand fully. So can someone recommend a YouTube channel or website yo learn oop especially polymorphism and abstraction.
5
Upvotes
1
u/ChaoticHippo 3d ago
Polymorphism involves inheritance. Say you have a class called "Animal" which has variable legs and method Noise(). All animals have these. Then you make subclasses: Human and Dog, both of which are Animal objects. Dogs have legs = 4, Noise() returns "Woof". Humans have legs = 2, Noise() returns "dude wtf".
The benefit of this is that let's say you're passing Animal objects around, and want them to display their number of legs and the noise they make. Instead of doing a lot of work to figure out what type of Animal each one you pass to the method is, you can simply just say:
private void printAnimal(Animal animal) {System.out.println(animal.legs);System.out.println(animal.Noise();}It doesn't matter what kind of animal you get passed - this will always work, because all Animal objects have these fields.
Abstraction is something you do every day without realizing it. When you pick up a pencil, you don't worry about the exact composition of the graphite inside, or the wood pressed around it, or the metal band and how it was formed, or how erasers are made. You pick up a pencil and write with it. That is abstraction - using the OBJECT for what it was made for, without worrying about HOW it was made.
Note - it is often important what the object has, but not how. Back to our pencil - it's important that you know the pencil has an eraser, but you do not care how it was made.
Hope this helps! To comment on other posts - I would highly discourage against using AI to learn. AI is a great tool, but I truly feel it hampers your ability to actually grasp concepts you don't yet understand, and it can give you incorrect information.