-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticKeyword2.java
More file actions
36 lines (29 loc) · 907 Bytes
/
StaticKeyword2.java
File metadata and controls
36 lines (29 loc) · 907 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
33
34
35
36
public class StaticKeyword2 {
public static void main(String[] args){
MobilePhone.displayType();
MobilePhone obj1 = new MobilePhone("Apple", 10000);
MobilePhone.displayInstanceVariables(obj1);
}
}
class MobilePhone{
String model;
int prize;
static String type = "Smart phone";
MobilePhone(String model, int prize){
this.model = model;
this.prize = prize;
//type = "Smart Phone";
}
public void dtx(){
System.out.println("Instance Method");
displayType(); //can access static mehtods
}
public static void displayType(){
System.out.println("Type is "+type);
//dtx(); cannot directly access instance methods
}
public static void displayInstanceVariables(MobilePhone obj){
System.out.println("model = "+obj.model+" "+"pize = "+obj.prize);
obj.dtx();
}
}