Difference between local and global variables with examples in Java - Core Java -Part -8

preview_player
Показать описание
JavaBasics Part 8 - Difference between local and global variables with examples in Java

Learn:

local variable java
instance variable vs local variable
instance variable in java
java variable declaration
scope of variables in java
static variables in java
difference between local and global variables with examples
class variable

=======================================
Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

Follow me on my Facebook Page:

-~-~~-~~~-~~-~-
========================================================
Please watch: "Selenium & Automation Interview Preparation - By Naveen AutomationLabs"
-~-~~-~~~-~~-~- Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

Paid courses (Recorded) videos:
📗 Get My Paid Courses at
Paid courses (Recorded) videos:
-------------------------------

✔️SOCIAL NETWORKS
--------------------------------

Support My Channel✔️Or Buy Me A Coffee
--------------------------------
✔️Thanks for watching!
देखने के लिए धन्यवाद
Благодаря за гледането
感谢您观看
Merci d'avoir regardé
Grazie per la visione
Gracias por ver
شكرا للمشاهدة
Рекомендации по теме
Комментарии
Автор

Just want to add few points after watching this video and did some practice. Let me know if any point is wrong I will appreciate.
Since main() method is static so we need to create object to access global variable inside main().
If we try accessing global variable inside sum() method which is non static, we don't need object, can directly access.
Same way we can call non static function inside non static function without using object but since main() is static function so if we want to call non static function(normal function) inside main() we have to call using object of class.
Also we can't access local variable of any function directly inside main() method using object. We can call only call function inside main() using object(not its variable) or global variable.


Naveen your tutorials are awesome. I have just started following your videos and every day my concept is getting better and better. I don't have words to show my gratitude.. Thank you very much.

RahulJha-bucv
Автор

Very simple concept, but you explain in much simpler way, which we understand very easily. Thank you so much Naveen!!!

utpalsarker
Автор

it was good session as always but Naveen i have question how to access variables such as i and j that you defined for method 'sum' in this example, which are outside the scope of main method?

charanjitsingh
Автор

thank you so much i had so many confusions which are not at all in my mind now i must say you are doing great job

priyankasuryawanshi
Автор

Great work for all of us! thank you...

devjewel
Автор

Can you please make a video on Class Variable too

jayanbhadiyadra
Автор

U shld also come up with casting and generics topics

rajeshjangid
Автор

Hi Naveen, your videos are very good and informative, can you make video for all permutation for particular string which was asked in many mnc.

alim
Автор

Watching the second time, , cuz sometimes lose driver between pages
and pages between classes😁

daisyd
Автор

Thanks for training videos.... They are awesome....Had a query in this video:
"In the diagram at the end why have you shown function in the object circle....Can it not be outside object circle in Java memory rectangle? "

nileshwairagade
Автор

Very understandable for freshers....tqqq sir

madhurivepareddy
Автор

Ur videos are excellent.. thank u so much Naveen

MyhappyWorld-gg
Автор

how can we access Global variables in the sum() method
can we use direct system.out.println(obj.name)
or we need to create object in sum() method as well to access name and age variables
Please confirm.

crazypro
Автор

Can we say that global variable is also known as instance variable? If not what is the difference between global and instance variable?

arunx
Автор

Sir If one get membership what benefits he can get ??

abhiranjansingh
Автор

In Java don't say global variables, they are instance variables.

alim
Автор

Hi Naveen,

One doubt, in sum() method, I was able to directly access & print global variable - name, age.
Question: Why in non-static method (sum() ) we can directly access global variable without creating object, any reason ?

Thanks

shailendrakumaromkar
Автор

inside public void sum method i tried to System.out.println(j); to print only value of i but its not printing any specific reason?

amitpuranik
Автор

Naveen, I am trying print System.out.print(j) but it does not print anything. Can you please help on this?

RajuDas-zngx
Автор

Hi Naveen,
I had this one doubt,
is class variables, global variables and instance variable, all are same or there is some difference, because as far as i see I don't find any difference.
Please clarify
thank you
Archana

archanatiwari