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

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

Telusko

7 лет назад

165,837 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Strawberry
Strawberry - 11.05.2023 20:52

It will not work. since i is an instance variable which is associated with the object of the class, but here we have not created any object for the class so memory has not gat allocated for i. But main js static, JVM called main by the class name, for the reason mentioned above non-static variable i is not accessible inside a static method.

Ответить
Neesha Neesha
Neesha Neesha - 21.01.2023 06:59

This code does not work because we cannot use non static variables in static method and if we want to use non static we have to make use of objects

Ответить
neeto nuvvu unda nappudu tanu evvaro neeto undali?
neeto nuvvu unda nappudu tanu evvaro neeto undali? - 05.12.2022 14:01

Cannot work because we cannot use non status variable in static method

Ответить
prianca m
prianca m - 02.12.2022 05:01

Such worst presentation

Ответить
Abhishek Solanki
Abhishek Solanki - 17.08.2022 22:44

Thank you sir, my doubt is now clear.

Ответить
Hashmath Ali
Hashmath Ali - 29.07.2022 12:13

because the class level variable is a non static and hence it need to create an object to store

Ответить
ALL ABOUT SAP
ALL ABOUT SAP - 22.07.2022 17:11

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

Ответить
Mahesh Kumar
Mahesh Kumar - 21.07.2022 21:01

It will not work because we created instance variable and we didn't created object or instance of the class without creating instance of a class it will not work . Instance variable always created when object is created.
if we use here object reference the it will work like d.i++;

Ответить
Prashu official461
Prashu official461 - 24.06.2022 09:51

no it will not work

Ответить
Jide Solanke
Jide Solanke - 20.06.2022 16:44

no you cannot access a non-
static variable from a static method

Ответить
YESHWANT D
YESHWANT D - 04.04.2022 14:44

No

Ответить
Sunil G
Sunil G - 29.03.2022 17:55

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

Ответить
8888 Sankalp
8888 Sankalp - 25.03.2022 16:41

No, because compiler first go in main
And there is no reference of i

Ответить
vignesh
vignesh - 05.03.2022 10:51

Keep rocking Navin

Ответить
Jaydeep Pal
Jaydeep Pal - 13.02.2022 09:41

non static field we cant access from static method

Ответить
Shubham Choudhary
Shubham Choudhary - 05.01.2022 08:33

How do i change non static class to static . Which use. function?

Ответить
SWAPNIL SHINDE
SWAPNIL SHINDE - 09.12.2021 08:58

No it raise error

Ответить
AdvenAkash
AdvenAkash - 23.10.2021 07:00

this code wont work because i is a non static variable

Ответить
Honey
Honey - 17.10.2021 16:41

Why non-static method can cal another non static method directly..?

Ответить
nisha pandey
nisha pandey - 16.10.2021 19:16

No it will not work as u suggested in previous video that only static variable can be declared with static method

Ответить