-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatic.java
More file actions
25 lines (24 loc) · 758 Bytes
/
Static.java
File metadata and controls
25 lines (24 loc) · 758 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
public class Static {
public static void main(String[]args){
friend friend1=new friend("spongebob");
friend friend2=new friend("patrick");
friend friend3=new friend("tanya");
friend.showfriends();
}
}
class friend{
// static = a keyword which belongs to class itself not to any specific object
//can be called without creating an object we do not need "this"
//provides utility methods like math.abs and etc math class methods
// shared resources saves memory
static int numofFriends;
String name;
friend(String name){
this.name=name;
numofFriends++;
}
static void showfriends()
{
System.out.println("you have total "+ numofFriends+" friends");
}
}