-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEx16ClassAbsInterface.java
More file actions
74 lines (62 loc) · 2.18 KB
/
Ex16ClassAbsInterface.java
File metadata and controls
74 lines (62 loc) · 2.18 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package JavaEntry;
// abstract class: using it we hiding certain details and showing only essential information to the user.
// Interfaces, hide certain details and only show the important details of an object.
abstract class UserDetails {
String name = "Banti Shaw";
String universityName = "SMU";
String getUserDetails(){
return name + " " + universityName;
}
}
class ForUseUserDetails extends UserDetails {
public String getName = getUserDetails();
}
interface Student {
String name = "Ganesh";
String universityName = "Unknown";
default String getStudentDetails(){
return name;
}
}
class ForInterfaceUse implements Student {
public String studentName = getStudentDetails();
}
// enum is a special "class" that represents a group of constants (unchangeable variables, like final variables).
enum Process {
TODO,
INDEVELOPMENT,
REVIEW,
DONE
}
public class Ex16ClassAbsInterface {
public static void main(String[] args){
// UserDetails userObj = new UserDetails(); // We can't create the object with abstract class.
ForUseUserDetails extendedUserObj = new ForUseUserDetails();
System.out.println(extendedUserObj.getName);
ForInterfaceUse interfaceStudentObj = new ForInterfaceUse();
System.out.println(interfaceStudentObj.studentName);
Process currState = Process.TODO;
Process devState = Process.INDEVELOPMENT;
System.out.println(currState + " " + devState);
switch(currState){
case TODO:
System.out.println("Work is on " + currState + " state");
break;
case INDEVELOPMENT:
System.out.println("Work is on " + currState + " state");
break;
case REVIEW:
System.out.println("Work is on " + currState + " state");
break;
case DONE:
System.out.println("Work is on " + currState);
break;
default:
System.out.println("No Work");
break;
}
for(Process enumItem : Process.values()){
System.out.println("Process name - " + enumItem);
}
}
}