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
Warren Buffett's Top 5 Stocks for 2023
Well, it’s the beginning of a new year, and what an awesome time to revisit the stock portfolios of the world’s best investors, like Mr. Warren Buffett, and check out what they’re holding for the year ahead. So, in this video, let’s look at Warren Buffett…
President Obama Credits Mom and Hawaii For His Love of Nature | National Geographic
It’s something to see, is it not? Amazing! It’s great to meet. Wonderful. Thank you for… We just diving in? Are we good? I think so. Okay, come on. Yeah, so I understand that you’re a big fan of your White House science fairs and that you seem to enjoy a…
A Bad Situation | Badlands, Texas
Have a visit with this [Applause] fella 211, so I’m going to be out South 118. How you doing? Just ging away? Well, the reason why I stopped you, you’re speeding 85 in a 70. I just am so sorry. I was so sure when they came back with a not-guilty verdict,…
Sales and Marketing + How to Talk to Investors with Tyler Bosmeny and YC Partners (HtSaS 2014: 19)
Talking, okay great. Um, so okay great, thanks for having me. So my name is Tyler, I’m the CEO of Clever and what I want to talk today is about sales, and I have a little bit of insight into this. I graduated college, I actually studied math and statisti…
Making Something Social Destroys the Truth of It
Making something social destroys the truth of it because social groups need consensus to survive. Otherwise, they fight; they can’t get along. Consensus is all about compromise, not about truth-seeking. Science was this unique discipline, at least in Natu…
Charlie Munger: How to Invest During a Recession
You mentioned we’re in a big bubble; can you elaborate on that and how is this likely to play out? Well, I think eventually there’ll be considerable trouble because of the wretched access; that’s the way it’s usually worked in the past. But when it’s goin…