Java Static Keyword: Class Level Members and Variables

#60DaysOfJava 📚 Day 17 Static Keyword (Java) 📌Static Keyword 🔹 Static is used to define class level members 🔹 It can be used with variables, methods, blocks, and nested classes 📊 Static Variable: 🔸 Shared among all objects of the class 🔸 Belongs to the class, not instances 🔸 Memory is allocated when the class is loaded 🔸 Stored in method area (Metaspace in modern JVM) 💡 Example: static String country = "India"; ⚙️ Static Method: 🔹 Can be called without creating an object 🔹 Belongs to the class 🔹 Used for utility/helper methods 🔹 Cannot access non-static members directly 💡 Example: static void displayIndiaPopulation() { System.out.println("billion"); } 🚀 Static Block: 🔸 Executes once when the class is loaded 🔸 Runs before object creation and constructors 🔸 Used to initialize static variables 🔸 Used to load configuration / register drivers 🔸 Used for one time setup logic 💡 Example: static String country; static { country = "USA"; } Nested class and static nested class we will see upcoming post 🤵 Follow Hariprasath V for daily more helpful resources. ♻ Repost Others also learn and grow together 👍 Hit if this was helpful. ✅ Save it future use. ================================================ #60DaysOfJavaWithHariprasathv6 #Java #JavaBasics #Programming #Coding #Developers #LearningJava #HighLevelDesign #SystemDesign #DSAChallenge #60DaysOfDSA #ProblemSolving #CodingJourney #Consistency #LearnByDoing #DataStructures #Algorithms #InterviewPrep #KeepCoding #Productivity #Focus #DreamBig #Java #SystemDesign #DataStructures #Algorithms #JavaDeveloper #DSA #CodingInterview #TechInterview #SystemDesignInterview #BackendDevelopment #SoftwareEngineering #JavaInterview #LeetCode #InterviewPrep #DataStructureAndAlgorithms #DesignPatterns #LowLevelDesign #Multithreading #SOLIDPrinciples #RESTAPI #BackendEngineer #CodeInterview #interviewtips #interviewexperience #Java #Programming #CoreJava #Learning #Developers #OOP #Java #Programming #Coding #Developers #JavaBasics

  • graphical user interface, website

Most Repeated Java Interview Question 💡 Are you able to overload / override a static method? ✔️ You can overload a static method ❌ You cannot override a static method We will see detailed explanation when we will explore overloading and overriding concept

To view or add a comment, sign in

Explore content categories