Java Programming: 16 - Overriding methods, drawing on a frame

preview_player
Показать описание
In this tutorial, we continue learning about inheritance by covering overriding methods. Technically, overriding methods isn't specific to inheritance, but we will learn more about that after a couple more videos.

You can override inherited methods by creating a method with the same signature as one that is inherited (same name, return type, and parameters). Or you can use Eclipse's code assisting to do that for you, as I do in this video.

You can use the super keyword to reference the instance of the base class, and use it to call methods or access variables. This is useful for when you need to override a method to add additional functionality, rather than replace it entirely.

The @Override is called an annotation, is optional, and isn't important to learn about right now.
Рекомендации по теме
Комментарии
Автор

I've been around the block a few times, searching for great Java tutorials. My search has now ended. Thank you!

bnewton
Автор

Very very good work.
Seriously.
Just watched all of those sequentially and feel like I've really learned something.
Thanks a lot for giving this to the Community.
It will make my learning all the smoother.
Can't wait for the following parts now.

PawFromTheBroons
Автор

@Gibbonator42685 Thanks for your kind words. As for other tutorials, they're all over, but it is hard to find good ones. That's part of the reason I began mine. I wasn't quite satisfied with what else was out there, and mine tend to include things I wish I had learned about early on.

Just remember videos like these are never a substitute for books, and certainly not for coding. Sometimes you just have to jump in and play around.

CodeMonkeyCharlie
Автор

Very well done! This tutorial gives the simple way to learn Java programming basics.

NomenOmen
Автор

Absolutely great video. I've watched them all now and really looking forward to your next one. Please keep up the great work.

samclacton
Автор

I've been stuck with JFrames for a while now and was almost ready to give up learning Java. You explain it so well and have helped me tremendously.

DominicPowell
Автор

Please add more. You are very easy to follow and understand.

bailinski
Автор

@15johnkim super refers to the base class instance. The way inheritance works is that there is a chain of instantiation, where ultimately the last link is the class you're actually creating an instance of, and the first is Object. In our case here, we have Object > Base > Subclass.

You can think of using "super" inside of Subclass as working with an instance of Base, just like how "this" is the instance of Subclass. I'll cover it in more detail in a future video.

CodeMonkeyCharlie
Автор

Yes, it will work exactly the same. The annotation is optional, but having it there will force the compiler to check that you are in fact overriding something (can catch mistakes), and it makes it clear that you are overriding an existing method.

CodeMonkeyCharlie
Автор

These are nice tutorials.
I hope you will make more of them, cuz they are really well explained.
Tnx.

Hara-lamb
Автор

Your videos are so great!!! Thank you for all of them!

Amerinidiot
Автор

@Gibbonator42685 One that I would highly recommend would be the programming methodology lectures that Stanford posted. Great professor. The only drawback is that lectures like those are generally at a slower pace than more targeted tutorial videos like what I try to create.

CodeMonkeyCharlie
Автор

I found this video very helpful and I'm learning a lot

HaimanotMBelay
Автор

If you only require what is implemented within the base class, and the base class is not abstract, then certainly it would be a better decision to use that than to extend it.

You should also favor composition and interfaces over inheritance.

CodeMonkeyCharlie
Автор

@SuperDpunisher Definitely not the end, I'll be making more when I find the time

CodeMonkeyCharlie
Автор

Yeah, I think the default draw color is always set to black, but maybe we shouldn't rely on that. It would probably be better to set it explicitly.

CodeMonkeyCharlie
Автор

Hi, I have watched all of your videos in order and followed along with eclipse on my computer. Great job. I have one question. I was exploring eclipse, and saw something called an android virtual device. Is that important to have?

jacobbronshteyn
Автор

Super refers to an instance, yet at the same time abstract classes cant be instantiated in an object

NoName-pzmk
Автор

very helpful video .. like the others ;)

Thegamer-ypqq
Автор

Why method sayHello() in the Constructor of Superclass is invoked like static, but this method defined in the Base like for instance of Base class? Thank you 

rvkvlad
welcome to shbcf.ru