You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Non Access modifiers - final, abstract, strictfp
39
+
40
+
### Java variables
41
+
the following are java variables
42
+
- Local variables
43
+
- Class variables (Static variables)
44
+
- Instance variables (non static variables)
45
+
46
+
### Java enums
47
+
They restrict variables to have a few pre-defined values
48
+
49
+
Example:
50
+
51
+
if we consider an application for a fresh juice shop, it would be possible to restrict the glass size to small, medium, and large. This would make sure that it would not allow anyone to order any size other than small, medium, or large.
52
+
53
+
```java
54
+
classFreshJuice{
55
+
enumFreshJuiceSize {Small, Medium, Large}
56
+
FreshJuiceSize size;
57
+
}
58
+
59
+
publicclassFreshJuiceTest {
60
+
61
+
publicstaticvoidmain(Stringargs[]) {
62
+
FreshJuice juice =newFreshJuice();
63
+
juice.size =FreshJuice.FreshJuiceSize.Medium;
64
+
System.out.println("size"+ juice.size);
65
+
}
66
+
}
67
+
```
68
+
69
+
### Inheritance
70
+
In Java, classes can be derived from classes. Basically, if you need to create a new class and here is already a class that has some of the code you require, then it is possible to derive your new class from the already existing code.
71
+
72
+
This concept allows you to reuse the fields and methods of the existing class without having to rewrite the code in a new class. In this scenario, the existing class is called the `superclass` and the derived class is called the `subclass`.
73
+
74
+
### Interfaces
75
+
In Java language, an interface can be defined as a contract between objects on how to communicate with each other. Interfaces play a vital role when it comes to the concept of inheritance.
76
+
77
+
An interface defines the methods, a deriving class (subclass) should use. But the implementation of the methods is totally up to the subclass.
0 commit comments