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
Who Is God? | Street Spirituality
Idea or doctor doesn’t good accident. Okay, hi! Which article book Islam me for such on fixing? What would a really quick way to know is mission individual people just want something, or some person to have faith in so that they can survive? And that’s w…
Economies and diseconomies of scale | APⓇ Microeconomics | Khan Academy
In the last video, we were able to construct here in red this long run average total cost curve based on connecting the minimum points or the bottoms of the u’s of our various short run average total cost curves. Each of those short run average total cost…
Video from Jeff Bezos about Amazon and Zappos
Hello, my name is Jeff Bezos. Uh, I started Amazon.com about 15 years ago. Uh, tons of stories from the early days. So we started the company in my house. Um, we didn’t have enough electric power in the house at a certain point. We only had about four em…
Hint to Adults - Kids Are Curious | StarTalk
I don’t know why people continue to concern themselves with getting kids interested in STEM fields. That’s a mystery to me because all kids are interested in STEM fields. It’s the adults that are the problem. The adults who run things, who wield resources…
An URGENT Warning For ALL Crypto Investors
What’s up guys, it’s Graham here. So, as usual, I had another topic that was planned to post today, but with everything going on, along with some really bad advice spreading around the internet, I decided it was best to postpone that video so that we coul…
This Particle Breaks Time Symmetry
Most processes in our universe are time reversible. In other words, the physics works the same way forwards or backwards. Which is why you can’t tell if I’m playing these videos normally or in reverse. People typically point to entropy as the only excepti…