In Java, static members belong to the class itself and are stored in class memory, while non-static members belong to individual objects and are stored in each object's memory. When an object is created, only non-static members are loaded into it; static members are never loaded into objects. Static members can be accessed using the class name without creating an object, whereas non-static members require an object reference. Each object has its own copy of non-static variables, so changes to one object's non-static variable do not affect other objects, while static variables are shared across all objects of that class.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
12th May 2026 - Core Java Demo Session 2Added:
Prepare the notes.
Yes. Revision all done. Okay.
Fine.
Now we guys are going to discuss about the next important thing in Java that is what do you mean by static keyword. Remember yesterday I discussed about what do you mean by a class and new keyword and I'm sure everybody's clear about it and if anyone has missed these lectures I again want to tell them please watch that lecture then only today's class will become clear like I'm seeing you people are attending today is your first class you missed yesterday's class, right? So, there are chances you might not have total clarity since it's a follow-up lecture of yesterday. But, however, try to understand how muchever you can then I'll share the link with you of the session that you have missed yesterday.
So, we are going to now look at what do you mean by static?
What do you mean by static versus non-static?
What do you mean by static versus non-static?
Let us try to understand this. Now see today people okay always you know you notice we start dividing the people. For example, you know, uh boys and girls, we might basically have different seating arrangements most of the time that we see in colleges or in schools and things like that where boys are on one side, girls on one side. I'm dividing I'm dividing the class into two part or probably we are you know dividing our complete country into different states correct now that's why you notice this all you know IPL matches I don't know what's there for people to fight so much you know RCB CSK and I see some of time some of the time At in the stadium, people they start hitting each other, right? And while people who are playing cricket, they are earning nice money and people who are unemployed, paying money, buying the ticket, they hit each other and then after that police complaints are happening. But again the whole concept of IPL to become popular is divide the audience because they understood the state sensitivity is there right. For example, you go to Maharashtra, you might say you speak in Marati. You come to Karnataka, you say you speak in Canada. But we forget we all are Indians, right? And we belong to the same country.
But there is okay something called as a division happened. We divided our country into multiple states. Sir, why are we talking about this?
See just like this whatever content that you write in your class we will divide the content of the class into two parts.
Okay. One is called as a static content and the other one will be called as a non-static content.
Whatever you write in a class now this class will specially have two categories of content.
Okay, one is static. So what does static means? And the other one is non-static.
What does it mean? So let's see this here again with one example.
I'll create a class.
Okay, this is the syntax.
Everybody listen carefully. Now in this class, I'm going to create one simple variable.
Okay. whose type is int. Meaning this variable x can store only integer value plus or minus 10 0 you cannot store 10.3 integer values allowed.
Now when you specify x to be int only integer value you can store in this variable x. Keep this in mind. We'll talk about variables little later for now this much is enough.
and another variable that I'll create.
I'll write static int y is equal to 20.
Observe carefully what I did. There is no static keyword return here. But at this line, I'm using static keyword.
Sir, what difference does it make? So, here is where the divide and rule policy right has started.
You have now divided this variables into two types.
Now this variable here which does not have static keyword is now called as non-static. And what does this mean?
And the variable that you see here I will be calling that as static. Sir what does this mean? Very simple.
When we create an object, when we create an object, a A1 is equal to new A. Everybody is now clear with object creation.
So when you now create an object for this class, when the object is created, what will happen?
Only the nonstatic member only the non-static member will be loaded into the object.
Okay, what will be loaded in the object?
Only the non-static member is loaded into the object.
Now anything that has static do not have the entry inside this object.
Static can never go to object. Again I'm repeating if you make something non-static the whole intention of the developer is let's take that non-static stuff.
Whatever is non-static, let's take that and put that inside the object.
Did you understand this here? So this non-static will go to the object.
But when you mark anything as static, it will not go to object. Sir, let me demonstrate this here for now. You guys don't know okay how to debug an application.
I'm going to debug and show you this later. I'll also teach you debugging in Java. Keep that in mind. Okay? For now, you don't worry about it. You just understand the concept.
Now, I'm creating a variable in text is equal to 10.
There is no static keyword here. If you observe the position, it's created inside class and outside the method.
Non-static should not be created within method. This is wrong. This is not non-static.
Non-static can be created here or you can create here. It should be outside method inside class.
I prefer creating here.
Now I'm going to create another variable that is also supposed to be outside method inside class.
Don't create here.
Wrong. It has to be outside method inside class. Now I'll create object a1 is equal to new a. Observe carefully.
Observe carefully. I will now run my program in debug mode. Okay, debug means every line what it does it will help me understand that now. So you need not ask your friend going forward, can you explain this program to me?
Because there's a thing with students.
They will start asking their friends, can you just tell me how is this program actually running? Let me right click debug as Java application.
And once I do that, you observe the application has stopped has to stop at this line. I did not save this program.
So I'm saving it and again running it.
Okay, carefully observe.
You will get lot of understanding here.
Now, okay, carefully observe.
Now you notice I'm at line 8. I'm at line 8. Now I will move to line 9. And you see object got created.
Can you see here?
When I now look at what is there in the object, what do you see?
Variable X is in the object. Did Y get loaded to the object?
No.
it did not get loaded to the object.
Understand again I'm repeating when you make anything non-static that will belong to object. You see it has gone to the object. So let's try once again. Let me make this also non-static.
Again let me show you here. Okay. Right now I am at line number eight. Now when you move from 8 to 9 object is created from 8 you move to 9 object created. Now what is present in object?
How come why got loaded?
Because it is non-static. Students, online people able to understand when you make anything as non-static that belongs to object and static does not belong to object. See we started dividing now just like IPL match. Yes. Now let's continue our discussion further. So non-static goes to object. Sir, this point is clear. But then what happens to static is static belongs to class directly.
You don't require an object to access.
Every class has one dedicated common memory. Every class has one dedicated common memory. Now this memory belongs to class.
Anything static, anything static that will go to class memory and anything that is non-static will get inside the object we divide it. If you make anything static, this is a class member. You make anything non-static, this is an object member.
Right? Like example, you might have two categories of rooms in the hotel, economy and luxury category. People are divided. You might have two kinds of seats in the plane. One business class, economic class. Economic class separate, business class separate. We dividing it.
Same way static non-static we dividing the member. Static belongs to class, non-static belongs to object. Till here things are clear everyone.
Okay. Everyone clear with this part?
Anyone any doubt right now itself you can tell me. If anybody has any doubts you can tell me right away and if no doubts I'll continue further.
Now anything that belongs to object anything that is within the object how to access that so what I'll do now I'll use the object's address A1 I'll use A1 which one it's all created outside method inside class static non-static where is it created you only see here inside class outside method. Okay, did you understand that?
Now observe here when you write A1, what does A1 holds?
What does A1 holds? You tell me.
What does A1 hold? Yes, you tell me.
A1, what is present inside A1, right? Print. Yesterday we printed right? Address of the object. A1 holds what? Address of the object. Yes or no?
When you write A1, this A1 has address. So using A1 with this address, I'm going to the object.
What does A1 has?
Address of the object. Using that address, I'm reaching the object. Dot you enter the object. And in that you want variable X.
Did you understand the syntax? How to access the content of object? Let's try again.
A1 means locating object. Dot means enter the object. And in that give me variable X.
And in that give me variable X. Observe here. Observe here guys. Now in this case I have this variable X and if I want to access this I will have to use I will have to use A1 dot X right a1.X observe here now what will happen? Okay.
So see here I'm at line 8. Now when you cross line 8 what got created?
Object. And inside that object there is variable x.
Now when I use this a1.x just see what is it printing.
So what did this do? A1 locates object dot enter the object and in that give me variable X. What does variable X holds?
10. Is this point clear? Online offline students is this point clear? Please do let me know. If yes, we will continue further and talk more about it. Is this part clear?
online students anyone any doubts okay now suppose I want to access static can you once again tell me static belongs to whom class since it belongs to class do not create object to access that use the class name what is the class name A using A you go to the class common memory dot enter the common memory and in that give me variable Y.
Example if I now make this variable as static.
Now keep one thing in mind that do not create object directly use class name and access it. Am I able to access?
Let's run this and see. Observe now.
Observe. Now I'm at line 8.
I will now proceed further. What is it printing?
And there's no object creation happening.
There's no object that is required to be created here because it is static.
access that member without creating an object till here I hope now some difference between static and non-static you people would have got it now okay now let's proceed further now we'll understand this more now okay suppose I now I have a static variable.
I have a non-static variable. Example.
Okay. Int x is equal to 10.
Now I'm going to write public static void main.
Okay. I'll create an object a a1 is equal to new a. Make it capital a.
All right. Now what I'll do is what I'll do is again I'll type a E2 is equal to new A observe now observe now so both are created inside class outside method yes both are created inside class outside method you're right now see object created A1 what is loaded into it non-static What is loaded into it?
What is loaded into it? Huh? Non-static.
Again, an object is created. How many objects created?
Two. Why two objects created?
Answer. You answer. Why two objects are created?
How many times new keyword is used?
Two times. Since new keyword is used two times, how many objects will be created?
Two objects. Yesterday we have discussed about it. How new keyword sends a request to class. Two objects are created.
Now whenever object is created, you see this variable X is getting loaded to that object.
First time object created X loaded.
Second time object created X loaded. Now the catch here is the variable x in object A1.
Listen carefully.
The variable X in object A1 and the variable X in object A2, they are different now. They're not same now.
They are different. Meaning I'll change the value in A1.
The value of X in A1 I'll change from 10 to 20. This value will not change because they are different variables.
Now I'll change this value to 30.
This variable value will not change.
The non-static variable present inside one object.
Okay. Is not same as the same variable X present in another object. You know variables.
Both the objects having variable X are different. Let me show you that here.
Observe.
What kind of variable is this now?
Non-static. Should I create object? See, I got an error. I cannot access with class name because this is non-static. What should I do?
Correct.
First observe here. First observe here.
I'll run this in slow motion.
Debug mode.
Observe. First object created. X is 10.
One more object created. X is 10. This object has X. This object also has X.
But now what I'll do in my next step is here I will type A1.X is equal to 20.
A1 dox is a variable x present in A1. I'm changing its value to 20. Will the value in A2 change?
It should not change because they are different. Observe.
Observe.
Now what does a a X holds the value in A1? 10. Now what the value got changed to? Did it change at line 9? Did it change? Now line 10 what is the value of x? Is this changing?
No. If you change the value of variable in one object that change you cannot see in another object because these variables are different.
Did you understand this?
Online offline students please tell me.
See how debugging is actually making things easy. And most of the times in academies we do not learn debugging only. I'll be teaching you debugging later which will make your understanding easier. So you need not rely on someone else and ask them how is this working?
Okay.
Everyone clear?
Students everyone clear?
Yes.
All clear. You tell me. Sager Git, you tell me now. Okay, you will only answer in the chat box. Other people will not answer. Sager Git, you tell me. I am at line 8. You tell me what is happening at line 8. Saga, you tell me what is happening at line 8. When I move from line 8 to line 9, what is happening in line 8?
What will happen in line 8?
Come on, you can at least answer that.
What is happening in line 8?
If I now move further, object creation.
Okay, when object is created, what is the value present in X? You see that and tell what is the value present? 10. Now I'm at line 9. What is line 9 doing? Going to A1 and the variable X value is being changed to 20. Observe did the value change 20. I change the value of x to 20 in a1.
But now when a2 is created, what is the value of x?
So my question is saga if you change the value of x in a1 will the value of x in a to change? No.
Because these variables are different.
Now that is what I meant here. Did you understand that now everyone? So how do we access these variables?
How do we print the output? We'll write system.out.print ln a1.x should print 20 because I changed the value here.
And a2 dot a2 do.x should print 10.
Everyone clear with this part?
Sure. So, let's go to our notes here.
Is that here? And just press Ctrl F.
Just press Ctrl F.
When a static variable is created, will all objects of that class also have that variable as a property? No. Objects cannot load static into it. That's it.
Whenever you create object, static cannot get loaded into it. Simple. It does not belong to object. But a beginner will do some mistake and he will get confused here which I will tell you further. But for now just search here for non static. Can you now read this loudly?
Point one clear. Next.
Did we discuss about that? Next.
Okay. What is the output of this program?
Which is a variable loaded in >> A1 X= 10. when you print 10. Example one clear. Okay, good. Example two. How many variables are loaded in A1?
Only X or both?
Both are loaded. Now why both are loaded?
Both are non-static. X is also non-static. Y is also non-static. So both the variables are loaded into A1. A1 do.x will print 10. A1 doy will print 20. Everybody clear with this?
Yes. Next point.
Every time we create object, non-static variable copies loaded to that object. Do you agree with that?
When you create object A1, X is loaded.
A2 X is loaded. A3 object again X is loaded. Next copy of variable in these objects are different.
Just now explain that is if you change the value of variable in one object those changes cannot be seen in another object. What is the variable?
X= 10 non-static. What is loaded in A1?
X what is that we are printing 10 changing the value to 20 what will it print 20 but A2 will continue to print I've taken this example everyone clear now let's continue further now whenever you create a non-static variable whenever you create a non-static variable you need not store some value in it always like I'm initializing with 10 delete not initialized initialized not initialized what we are telling if you do not store any value in X whatever its data type so-called as Int we have a separate lectures on data type.
Whatever the data type you see here int.
For this there is a fixed default value zero. If you don't initialize non-static variable for int automatically take zero value. You want to store decimal value. So we'll make it float.
Now you can store decimal values. But if you don't store anything, got it. This is called as a default value and that is what we are mentioning here. Read it.
Okay. It is not mandatory to initialize non-static variable depending on data type automatically.
default value will get stored in it.
Okay. So I'm not storing anything. What will it print?
Very good.
Now static variable. Can you read this loudly?
>> Correct.
Now to access static variable we have following options.
Let's see that here. Now I will now change this to int.
I'll store 10.
Make it static. Moment I do that you see there's a warning here because you're accessing static with object. And what it says which means it's telling you're wrong.
It's telling you're wrong. But still though you have done wrong. When you click on the run button though you have done wrong. When you click on the run button our Java compiler will replace A1 with capital A and will end up giving us an output.
It's telling you're wrong. Correct it.
But if you don't correct it will autocorrect internally and give you output. So this is a wrong approach.
What is this?
Never do this. But this will work. And that's why students will get confused and say static also can be accessed by object. It belongs to object. Wrong. See very clearly the information it's given.
It should be accessed in a static way.
The other way of accessing that which is the most preferred one class name. And the other way of accessing that is directly variable name. These two are preferred one. This is wrong one. However, there are three approaches.
And if you don't store anything, this also takes default value. What is the default value? Three times printing. 1 2 3.
So can you now read this?
What's the first one?
>> Second one.
Third one.
Next.
Is this clear? Now what is the output?
What is the output?
Will this work?
>> Yes. But that is wrong. Now observe static value whenever you make any variable static throughout your program there is only one static variable see understand what I try what I'm trying to tell you is I created class A okay now this class A I'm creating one static variable static int x is equal equal to 10.
Now this class common memory, this class common memory will have only one copy of static variable present in it.
This class common memory has only one copy of static memory. Unlike object, every object has separate variable x.
But this class has only one static variable.
And if you change this value to 100, then these changes are applicable to the whole class because a complete class has only one static variable.
Right? Are you understanding this?
Everyone did you understand this? online student see now what I'm telling I made the variable static I'll store the value 10 now what am I doing is I'm accessing a dox currently the value is 10 but now when I do a dox is equal to 100 this main value itself this main value itself is changed to what 100 this itself got changed internally. Now so this is no longer 10. Now after this whenever you use a dox it will remain to print 100 because you have changed the main value. What is it printing now?
Can you just see this here? What are we doing now?
I change the value. So this main value itself is changed to 100 because there's only one variable X which is static.
Static concept is what? Only one.
Non-static is equal to number of objects created.
Okay. If there is non-static two objects created then two non-static members are there. Intex non-static 100 objects created then 100 X variables are present in object. Static means only one and if you change the value main value is changed. Is this clear? Online students, offline students, please tell me.
Yes, we gave you access in the morning recorded class. Anybody did they watch this lectures?
Huh? Anybody try to do that?
You didn't already. We gx in the morning.
When you made the payment when you made the payment, >> huh?
>> Previous no existing who made the payment? You'll get the access later.
I'll be giving it to you. I'm asking about other students. Did you access that? You accessed it. Hey, morning only we gave you the access.
>> I don't I added one Excel I got in the morning. Whoever made the payment yesterday.
Yesterday you did the payment.
>> What's your name?
>> Okay. What? What?
>> Okay. Let me just check that once.
Okay. You you know will get an WhatsApp message today before end of the day. how to access your portals and start going ahead of my live classes. Watch the previous recorded, go ahead of me. So live classes will become more interesting.
Okay. So today as per our recorded series I have just completed I have just completed in core Java static courses.
This is completed. So tomorrow we are going to discuss about types of variables. This is our tomorrow's lecture what it is going to be. Okay. So you study this and come tomorrow.
Okay. Your understanding will be very much better because when you come to live class sir I also paid yesterday.
Have you won shika? Okay. But I did not get the access. Okay. Okay. I think the WhatsApp message was not shared by the staff to you. I will ask them to share it again.
Okay. Right.
And if you don't get it, just WhatsApp again. They will share your email ID already. You know passwords we will be sharing it to you. Okay. That's it guys.
Today's class ends here and again I'll see you tomorrow continue with a further lecture tomorrow. Okay, bye. Practice well.
Handwritten notes you prepare and we'll handwritten notes you prepare and will against you.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29











