Static - Variable, Method, Block, Nested Class in Java

Duration: 21 min

This video lesson is available to enrolled students.

Return to /learn/ASRB-ICAR-T3-T4-INFORMATION-TECHNOLOGY-PRELIMS-MAINS/oops-with-c-java/oops-with-java/static-and-final/asset-static-variable-method-block-nested-class-in-java after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. Prelims: General Knowledge: Physics Chemistry Biology History Geography Polity Indian Economy Static General Knowledge GK- Current Affairs Environment
  2. Prelims: General English: Vocabulary Noun Pronoun Adjectives Preposition Articles Direct and Indirect Speech Tenses Conjunction Subject Verb Agreement (Verb Noun Agreement) Modals Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing) Sentence Correction (Error Correction) Sentence Completion (Fill in the blanks) Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions) Cloze Test (Cloze Passage) Verbal Analogy (Word Based Analogy) Sentence Construction Adverb Verb
  3. Prelims: Quantitative Aptitude: Percentage Ratio and Proportion (Ratios) HCF LCM Divisibility Rules Average Sequence and Series (Series) Number System Powers and Exponents (Surds and Indices) Algebra Profit and Loss Simple Interest and Compound Interest Time and Work Pipe and Cistern Speed Time and Distance Mixture and Alligation Mensuration and Geometry Age Problems Partnership Statistics Data Interpretation Arithmetic
  4. Prelims: General Agriculture: Agriculture in India and Tripura Natural Resource Management Fundamentals of Crop Production Horticulture Crop Improvement Crop Protection Social Science
  5. IT Mains: Operating System: Introduction to OS Process Management CPU Scheduling Process Synchronization Threads & Process Creation Deadlock Memory Management Virtual Memory Disc Scheduling File Management Distributed Systems
  6. IT Mains: Computer Networking: Introduction to CN DLL: Access Control DLL: Flow Control DLL: Error Control Data Link Layer - Ethernet Net Layer: IPv4 & Proto Net Layer: IP Addressing Net Layer:Routing Protocol Transport Layer Services TL: Congestion & UDP Application Layer Hardware Basics Network Security
  7. IT Mains: DBMS: Basics of DBMS ER Diagram Relational Model & Functional Dependencies Keys & Integrity Constraints Normalization (1NF - BCNF) Decomposition Properties & 4NF Relational Algebra SQL Relational Calculus Transaction Management Concurrency Control Database Recovery Big Data Systems Database Security & Authorization Enhanced Data Models NoSQL
  8. IT Mains: Software Engineering: Fundamentals of Software Engineering Software Requirements and Quality Assurance Software Design, Estimation and Metrics Software Testing Software Maintenance and Configuration Management
  9. IT Mains: Data Structures & Algorithms: Introduction to DS Array Stack Queue Linked List Tree Graphs Hashing Algorithm Analysis Time Complexity Analysis Sorting Algorithms
  10. IT Mains: OOPS with C++ & Java: C Fundamentals OOPS with C++ Java Fundamentals Array, String, IO & References OOPS with Java Generic & Collections Multithreading File Handling & I/O
  11. IT Mains: Python: Introduction to Python Tokens, Variables, Data Types, I/O Operators & Expressions Control Flow & Looping Collections & Strings Functions & Modules
  12. IT Mains: Website Development: Website, Browser & Services Internet Fundamentals Web Design & Development Protocols & Services Web Publishing & Hosting Server Side & Security Emerging Technologies HTML Basics HTML5 CSS JavaScript-Basics .Net Programming PHP
  13. IT Mains: Mobile App Development: Mobile Computing Multimedia
  14. IT Mains: Linux / Windows Server Admin: Unix OS Linux OS
AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This lecture introduces the Java static keyword within OOPS, covering static variables, methods, blocks, and nested classes. It begins by defining static members as belonging to the class rather than individual objects, emphasizing that only one copy exists and is shared by all objects. The instructor uses a table to categorize where static is used: variables, methods, blocks, and nested classes. A static variable example uses a Student class with a static college field, demonstrating that both objects share the same value. Static methods are explained as unable to use this or super, and they can only access static members; attempting to access non-static members from a static context causes a compile error. Static blocks are introduced as initialization blocks that run once when the class is loaded, before main(). Finally, static nested classes are defined as classes declared static inside another class, which can be instantiated without an outer class object and can only access static members of the outer class. The lecture uses code examples, console output, and red annotations to reinforce each concept.

Chapters

  1. 0:00 – 2:00 00:00-02:00

    The video opens with the title 'OOPS with Java' and highlights 'Static & Final' using a red pen, then boxes the word 'Static' to signal the lesson focus. The instructor transitions to a 'Static Keyword' slide stating that static creates members belonging to the class rather than individual objects. A table titled 'Where is static used?' lists Variable, Method, Block, and Nested Class, with red underlines emphasizing key phrases such as 'belong to the class rather than to individual objects' and 'Only one copy exists, shared by all objects.'

  2. 2:00 – 5:00 02:00-05:00

    The 'Static Keyword' slide continues with bullet points explaining that a static member can be used without creating an object via ClassName.member, that only one copy exists shared by all objects, and that it is loaded in memory once when the class is loaded. The instructor adds handwritten red boxes labeled 'id =' and 'n =' above a 'class dec (object)' note, and draws a red rectangle around 'ClassName.member' to emphasize direct class-level access. The table rows for Variable and Method receive checkmarks as the instructor gestures through each use.

  3. 5:00 – 10:00 05:00-10:00

    The table expands with a 'What it means' column, and the instructor annotates the Block row with a handwritten 'static init' label. The lesson then moves to a 'Static Variable' slide stating that a static variable is shared by all objects and only one copy is created for the class. A Student.java code window defines 'static String college = "ABC College";' with a display() method printing rollNo and college. The console output shows '101 ABC College' and '102 ABC College', with red notes reading 'static var: college', 's1 rn=101', and 's2 rn=102' to illustrate shared state across two objects.

  4. 10:00 – 15:00 10:00-15:00

    The 'Static Method' slide lists rules: a static method can directly access static members but cannot directly access instance members, it cannot use this or super, it cannot be overridden (same signature in a subclass is method hiding), and the JVM must call main() without creating an object. A Main.java example shows a static show() method where 'System.out.println(a)' is labeled '// ERROR: non-static from static context' while 'System.out.println(b);' is valid. Red circles highlight the main method and the static method call to demonstrate execution without object creation.

  5. 15:00 – 20:00 15:00-20:00

    The 'Static Block' slide explains that static blocks are used to initialize static variables and execute once during class loading before the main method. A flowchart visualizes class loading, static block execution, and main method execution. A code example demonstrates a static block initializing a variable to 100 before main() prints it. The lesson then transitions to 'Static Nested Class', defining it as a class declared static inside another class that can be created without an outer class object and can access only static members of the outer class.

  6. 20:00 – 20:54 20:00-20:54

    The static nested class code example shows 'class Outer { static int data = 50; static class Inner { void show() { ... } } }', demonstrating the creation of an Inner object without an Outer object and calling its method to print the static variable data. Red annotations emphasize the static keyword on the Inner class declaration and the access to the outer class's static member, reinforcing that static nested classes operate independently of outer class instances.

The lecture follows a structured progression from definition to application. It starts with the core principle that static members belong to the class, not objects, then systematically covers each use case: variables (shared state), methods (no this/super, no instance access), blocks (one-time initialization at class load), and nested classes (independent instantiation). Each concept is reinforced with a code example and console output, using red annotations to draw attention to critical syntax and error conditions. The key exam-relevant takeaways are: static variables are shared (one copy), static methods cannot access instance members or use this/super, static blocks run before main(), and static nested classes do not require an outer instance.

Loading lesson…