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

Duration: 21 min

This video lesson is available to enrolled students.

Return to /learn/RPSC-PROGRAMMER/paper-2-programming-language-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. Paper 1 | Reasoning Test: Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Syllogisms, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Seating Arrangements, Blood Relations, Puzzle Solving (Puzzles), Venn Diagram, Analogy, Ranking, Order and Sequence, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Selection Decision Table (Decision Making), Logical Sequence Of Words, Cubes & Dices, Analytical Reasoning (Counting Figures Reasoning), Calendar, Alphabet and Word Tests, Numerical Reasoning, Number System, Averages, Mixtures and Alligation, Percentages, Series Completion, Analogy and Classification, Patterns in Two-Dimensional Figures, Coding and Decoding, Mathematical Operations, Direction Sense, Algebra, Logical Deduction and Induction, Syllogisms and Venn Diagrams, Critical Reasoning, Order, Ranking and Sequence, Reading Comprehension, Profit, Loss and Discount, Constraint Puzzles, Speed, Time and Distance, Traverse Surveying, Ratio and Proportion, Time and Work, Mensuration, Permutations and Combinations, Clocks and Calendars, Data Interpretation, Assembling and Grouping of Shapes, Transformation of Shapes, Three-Dimensional Patterns and Visualization, Cubes and Dice, Vocabulary, Blood Relations, Data Sufficiency
  2. Paper 1 | Numerical Analysis: Number System, HCF LCM, Percentage, Ratio and Proportion (Ratios), Average, Sequence and Series (Series), Powers and Exponents (Surds and Indices), Algebra, Statistics, Data Interpretation, Mental Ability, Arithmetic, Logarithm, Profit and Loss, Simple Interest and Compound Interest, Speed Time and Distance, Mixture and Alligation, Mensuration and Geometry, Permutation and Combination, Probability, Sequences and Series, Powers, Surds and Logarithms, Subject-Verb Agreement, Sentence Completion, Geometry, Sentence Structure and Correction, Data Sufficiency, Trigonometry, Measurement and Quantity Take-Off, Signal Space and Optimum Detection, Probability, Statistics, Algebra, Time and Work, Speed, Time and Distance, Data Interpretation, Graph Theory, Combinatorics
  3. Paper 1 | General Knowledge: State Wise GK, History, Geography, GK- Current Affairs, Static General Knowledge, Polity, Indian Economy
  4. Paper 1 | DBMS: Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, SQL, Transaction Management, Concurrency Control, Relational Calculus, Database Security & Authorization, Database Recovery
  5. Paper 1 | Data Communication & Network: Introduction to CN, Data Communication, DLL: Access Control, DLL: Flow Control, DLL: Error Control, DLL: Framing, Data Link Layer - Ethernet, Net Layer: IPv4 & Proto, Net Layer: IP Addressing, Net Layer:Routing Protocol, Transport Layer Services, TL: Congestion & UDP, Application Layer, Network Security, Security in Mobile and Wireless Computing, Input Output Organisation, File Management, Hardware Basics, Terms & Abbreviations, Protocols & Services, Network Access Technologies, Cyber Safety and Security, Basics of COA
  6. Paper 2 | System Analysis & Design: Fundamentals of Systems and Information Systems, SDLC and Development Approaches, Fundamentals of Software Engineering, Software Requirements and Quality Assurance, Software Documentation and Software Requirements Specification (SRS), SDD and Quality Assurance, Software Design, Estimation and Metrics, Software Testing, Software Maintenance and Configuration Management, Security, Risk Management & Maintenance, extras
  7. Paper 2 | Programming Language (Java): Java Fundamentals, OOPS with Java, Array, String, IO & References, Generic & Collections, Multithreading, Java, Miscellaneous, Control Flow, OOPS with C++, Stack, C Fundamentals, Arrays & Pointers, Object Oriented Technology, Control Flow & Looping, Introduction to Python
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…