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
See How Ancient Past and Present Meet in This Coastal Town | National Geographic
(soft music) [Gabriel] This is Huanchaco. This is my hometown. Huanchaco is a small fishing village that is north of the city of Trujillo, and it’s a very rich place in archaeological sites. There has been a continuous occupation in this area for more th…
Introduction to currency exchange and trade | AP Macroeconomics | Khan Academy
What I want to do in this video is think about how exchange rates can affect trade, and actually we can even think a little bit about how they might be able to affect each other, although we’ll go into a lot more depth in that in future videos. So let’s …
Conditional probability tree diagram example | Probability | AP Statistics | Khan Academy
Accompany screens job applicants for illegal drug use at a certain stage in their hiring process. The specific test they use has a false positive rate of 2% and a false negative rate of 1%. Suppose that 5% of all their applicants are actually using illega…
Under Sea Ice in Antarctica | Explorer
NARRATOR: Rod Bud is the safety supervisor and is responsible for bringing these scientists back home alive. ROD BUD: Fins on, we’re good to jump in the water. NARRATOR: He’ll be the first one in to ensure conditions are safe for the rest of the team. …
The Sky Table | Barkskins
[music playing] [thud] [panting] [thud] [thud] [thud] Ah. [thud] [cracking] [branches crunching] Excellent work, [inaudible] Sal. Come with me. There are more that need to be pulled from the sky. This way. [birds singing] I might be of help if you tell me…
15 Signs You’re Burned Out, Not Lazy
Over 70% of professionals feel burnt out at some point, yet many dismiss it as mere laziness. But the great news about burnout is that it’s solvable. The bad news about laziness is that, in this video, we’re about to call you out. Here are 15 signs you’re…