0% found this document useful (0 votes)
13 views10 pages

Understanding Static in Java OOP

The document discusses the use of the static keyword in Java, which allows class members to belong to the class itself rather than individual instances, optimizing memory usage and providing utility functions. It covers static variables, methods, blocks, and nested classes, along with their advantages, limitations, and best practices. The conclusion emphasizes the importance of using static members carefully to maintain object-oriented programming principles.

Uploaded by

bhartiprince829
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views10 pages

Understanding Static in Java OOP

The document discusses the use of the static keyword in Java, which allows class members to belong to the class itself rather than individual instances, optimizing memory usage and providing utility functions. It covers static variables, methods, blocks, and nested classes, along with their advantages, limitations, and best practices. The conclusion emphasizes the importance of using static members carefully to maintain object-oriented programming principles.

Uploaded by

bhartiprince829
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

RCC Institute of Information Technology

Topic: Use of static


[ Continuous Assessment -1 ]

Name: Prince Bharti


Clg. Roll: IT2023103
Univ. Roll: 11700223067
Stream: IT
Year: 3rd
Sem: 5th
Sub. Name: OOPS
Sub. Code: PCCCS503
Abstract
The static keyword in Java plays a crucial role in object-
oriented programming by allowing class members—
variables, methods, blocks, and nested classes—to belong
to the class itself rather than individual instances. This
shared nature of static members helps optimize memory
usage and provides convenient access to utility functions
without object creation. This presentation explores the
different uses of static, including variables, methods,
initialization blocks, and nested classes, highlighting their
advantages, limitations, and best practices for effective
use in Java programming.
Introduction to Static
• `static` is a keyword in Java used to define
members (variables, methods, blocks, nested
classes) that belong to the class rather than an
instance.
• Static members are shared by all objects of the
class.
• Helps save memory and provide utility methods
without creating objects.
Static Variables
• Also called: Class variables
• Declared using static keyword inside a class.
• Stored in method area (common memory).
• Shared across all instances.
• Use case: Counting objects, global configuration.
Static Methods
• Belong to the class and can be called without
creating an object.
• Can only access static data directly.
• Cannot use 'this' or 'super'.
• Use case: Utility methods like [Link](),
[Link]().
Static Blocks
• Used to initialize static data.
• Runs once when the class is loaded into
memory.
• Commonly used for setting up configurations
or loading drivers.
Static Classes (Nested)

• Only inner classes can be declared static.


• Can be accessed without an object of outer
class.
• Good for grouping utility/helper classes.
Advantages & Limitations

• Advantages: Saves memory, no need for


objects for calling methods, useful for
constants.
• Limitations: Cannot access non-static
members directly, reduces OOP flexibility.
Conclusion
• `static` is class-level scope in Java.
• Improves performance & utility in certain
cases.
• Best used for constants, counters, and helper
methods.
• Should be used carefully to maintain OOP
principles.
References
• Herbert Schildt – Java: The Complete Reference, McGraw-Hill
Education, 12th Edition.

• [Link]
ming-oops-concept-in-java/

• [Link]

You might also like