-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStaticClass.java
More file actions
32 lines (25 loc) · 791 Bytes
/
Copy pathStaticClass.java
File metadata and controls
32 lines (25 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class StaticClass1
{
int x; //instance member variable
private static int y; //static member variable private not accessible outside of the class
public void func1() {System.out.println(" This is from func1 ");} //instance member function
public static void func2() {System.out.println("static func2");} //for this func accessiable only static variable
//static class
static class Test
{
public static String me = "Programmer";
}
}
public class StaticClass
{
public static void main(String[] args)
{
//create object
StaticClass1 st1 = new StaticClass1();
StaticClass1 st2 = new StaticClass1();
//accessing without an object
//StaticClass1.y = 5; //not accessible
StaticClass1.func2();
System.out.println(StaticClass1.Test.me);
}
}