Lakhyadeep Sen’s Post

Another important concept while learning object oriented programming was understanding how variables behave inside a program. Depending on where a variable is declared and how it is used, Java treats it differently. Things that became clear : • local variables are declared inside methods and exist only during that method execution • instance variables are declared inside a class but outside methods, and each object gets its own copy • static variables belong to the class itself and are shared among all objects • local variables do not get default values, while instance and static variables do • the place where a variable is declared affects its lifetime and accessibility Seeing these differences made it clearer how memory and data management work inside a Java program. Understanding variable behaviour also helps avoid common mistakes when writing larger programs. #java #oop #programming #learning #dsajourney

To view or add a comment, sign in

Explore content categories