Unit 5 CS

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Public/Private

Constructor

Methods
● Void
● Return
● toString

Static

Static variables belong to the class, with all objects of a class sharing a single static variable.

Static methods cannot change non-static variables(reverse works)

Local Variables:
Scope: Limited to the block of code where they are declared (e.g., within a method, constructor,
or a block).
Lifetime: Created when the block is entered and destroyed when the block exits.
Usage: Used for temporary storage within a method or block of code.

Instance Variables (Non-static Fields):


Scope: Belong to an instance of a class (object).
Lifetime: Created when an object is instantiated and exists as long as the object is in memory.
Usage: Used to represent the state of an object.

Static Variables (Class Variables):


Scope: Belong to the class rather than an instance of the class.
Lifetime: Created when the class is loaded into memory and persists as long as the program is
running.
Usage: Shared among all instances of the class and typically used for constants or variables
that should be shared across instances.

This

You might also like