7.14 Why Non-Static variables does not work in Static method in Java?

preview_player
Показать описание
Trainer: Navin Reddy

Follow on Facebook:

Subscribe to our other channel:
Telusko Hindi :

Subscribe to the channel and learn Programming in easy way.

Regards,
Navin Reddy
Рекомендации по теме
Комментарии
Автор

this java playlist is best on the youtube.

ApexSpeedster
Автор

Listening to your classes is enough to crack a java interview. Tq so much for such wonderful work Navin...

tripurarisiddartha
Автор

Sir! I don't know how i can explain you! You just change my mind and life! I wish long live and God to be with you always! Thank you so much for your great and amazing tutorials that i am becoming addicted for!!!! ! And God bless India that giving us a brother like you! Respect

ethiopiahageriehagerieethi
Автор

This explanation actually helped me a lot to understand the subject better. Thank you sir!

MrBatraaf
Автор

Wow... This makes perfect sense. You have no idea how many videos I've watched to try and get this concept, but here you explain it perfectly.
Thanks a tonne mate! You've made my day, can't wait to check out more of your videos :D Much love and gratitude, from Sydney Australia <3

formlessavatar
Автор

You are a great teacher. I have been following you on youtube.com for more than 2 years. You really helped me a lot. Thanks a lot. May God bless you!!!!

sukhrobmatchanov
Автор

Till today this is best java tutorials. Im sure even after next 10-20 yrs this tutorial is THE BEST ONE.

sunilg
Автор

What if we call the method increament by obj1 and increasing the value num1 ?

shwetashrivastava
Автор

Thanks a lot sir!!!Bet u solved an important doubt of many programmers!!!

vidurwadhwa
Автор

Reduced the youtubu playspeed and hence understood 🤗

josephbabu
Автор

It doesn't work, bcoz we cannot use non static variable inside a static method

spandanaspandu
Автор

You need to mention in what part of the memory are static variables stored. They are stored in heap and local variables are stored in stack.

sameeruj
Автор

but the java main method is static right? but we still use non-static variables inside our main function(), how is it possible will anyone please help me with this doubt?

aswink
Автор

2:00 you said by mistake "obj3 has the value of num2 as 4" but it should be "obj3 has the value of num1 as 4". Thanks for the video. You are an amazing teacher!

thestarinthesky_
Автор

Not work i is non static and at the classloading time static varibles gets memory first and u use i in main method

sourabhyadav
Автор

Hello sir..My name is Seetesh Gupta..and i m from Indore...The answer of your question is that->int i=8 will not be accessible in the main function...because main function is static and the int i=8 is not static variable...if we want to access our variable i(which is non static), we have to create an object to access it in the main function..

seeteshguptasg
Автор

Another life saver video before my Java midterm hehe. Thank you so much!

wanej
Автор

The code gives error, because we should not use non static variables in static methods

bhargavponduri
Автор

Hello Sir as you said static variable can be used in not static method .. what happens when i declare a variable as a static in a Class and incremented using constructor (inside a constructor) then in the Main Method calling a staic variable using class name and creating an object please explain me
public class AppStaticTest {

public static int multiplier = 7;
public static void main(String[] args) {

StaticTest.numInstances = 10;

StaticTest firstInstance = new StaticTest("1st Instance");
+ " is instance number " +

StaticTest secondInstance = new StaticTest("2nd instance");
+ " is instance number " +

StaticTest thirdInstance = new StaticTest("3rd instance");
+ " is instance number " +

}

}
public class StaticTest {
public static int numInstances = 0;
private String name;

public StaticTest(String name) {
this.name = name;
numInstances++;
}

public static int getNumInstances() {
return numInstances;
}

public String getName() {
return name;
}
}

girijagirija
Автор

Can't we access non-static variables without creating an instance in the main method? Please help

allaboutsap