yego.me
💡 Stop wasting time. Read Youtube instead of watch. Download Chrome Extension

Java Lesson 16 | Final and Static Methods


2m read
·Nov 3, 2024

Hey, this is Jake with Maads 101. It's going to be another Java tutorial.

Today, I'm going to talk about two more different kinds of methods. I talked about abstract methods in the last tutorial, and this is going to be relatively brief, but I'm going to talk about static and final methods.

I already talked about static and final variables, so if you remember, a final variable could not be reassigned, and a final method cannot be overwritten. That's final! This is the method you can't override. To do that, you would just put final before it, like final public void print(), no parameters, and all right! That method could not be overwritten. I'm not going to go through a whole, you know, making a superclass and this and that to prove it, but just know it can't be overwritten.

The next one I'm going to talk about is a static method. So, let's say I had a method in this class. This is going to be an example of it just in this main class, and I had, like, and it was outside the main method: public void print(). I tried to call print, and I'm getting an error here because I need an object to call the method.

I could do this: MacHeads m = new MacHeads(); and I would be creating an object of this class, the MacHeads type, and then do m.print(). Or I can do something much simpler, which is make it static. So, public static void print()—and public static means I do not need an object to call this method.

So, if I just print it out, "Hello," and that's why it makes a lot of sense if this is static. But public static void print(), this public static void main(), and then I can just do print()—no errors because it's static.

I believe you can also put static before public; it doesn't matter. But yeah, so I'll just do public static, but you can put it before, so public static void print(), and I don't need an object to call this method because static methods don't need objects to be called. And there it goes! It prints "Hello."

So, I just want to talk about what's coming up next. In the next couple of tutorials—or yeah, I'm going to be talking about GUI, graphical user interface, like, you know, windows and buttons and graphics and stuff like that.

I didn't cover all of the Java basics, but I covered a lot of them, and what you'll need to know to start making GUI. The only reason I actually started making these tutorials on the basics was so that I could eventually start making Java GUI tutorials.

So, the next tutorial is going to be the first GUI tutorial, and I'm just going to be talking about creating a window and a few different ways to do that.

So, see you next time!

More Articles

View All
How to Finally Defeat Procrastination and Stop Wasting Time
Let’s be honest, you’re probably procrastinating while watching this video. And because of this, I’m going to keep this as practical and concise as possible. In life, you’re often deciding whether to approach or avoid something. You’re always making a jou…
The History of Magic | StarTalk
What’s this with Escape artists? I never was as enchanted by that as others have been. When you’re talking about a escape artist, you’re really talking about Houdini and then a lot of knockoffs after that. Houdini, in the early 20th century, a man born in…
How To Use Your Intuition
Hello, Airlock! Sir, welcome back. You know, some people have got the intuition of a wooden spoon, right? They struggle to make quick decisions, they can’t read a room, and they lack in the creativity department. Intuition is one of those things that’s no…
Sequences and domain | Sequences | Algebra I | Khan Academy
The focus of this video is going to be on sequences, which you have hopefully already seen. If you don’t know what a sequence is, I encourage you to review those videos on Khan Academy. But we’re going to focus on how we can generate the same sequence wi…
Request for Startups: Government 2.0 - Michael Seibel
Hello, my name is Michael Seibel and I’m the CEO of Y Combinator’s accelerator. Today, I’m here to introduce a new request for startups. Request for startups are a project that we do to inspire founders to apply to YC with new and interesting ideas. Toda…
Exclusive: Russian Foreign Minister Sergey Lavrov Describes the War With the US and How to End It
Minister Le, thank you for doing this. Um, do you believe the United States and Russia are at war with each other right now? I wouldn’t say so, and uh, in any case, this is not what we want. Uh, we would like to have normal relations with all our neighbo…