Lecture 5 access control and static keyword
Lecture 5 access control and static keyword
Lecture 5
Prof. Anita Agrawal
27-01-25
In today’s session…
Garbage collection
Access Specifiers
Static keyword
It is applicable to
blocks
variables
nested classes
methods
Ways of initialization:
Directly: modifier(if any) static var_type var_name;
Example: public static int x =2;
or……….
Declare a static block
Example: static int x;
static {
x = 2;
}
staticcar.java
18 Anita Agrawal CS F213
Observations for static
Any object can change the value of the class variable, but
class variables can also be manipulated without creating
an instance of the class.