FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/interfaceExamples/IntefaceRules.java at master · sivakurapati/Java-Programs · GitHub
sivakurapati
/
Java-Programs
Public
forked from
divScorp/Java-Programs
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs
/
interfaceExamples
/
IntefaceRules.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
64 lines (53 loc) · 1.67 KB
Breadcrumbs
Java-Programs
/
interfaceExamples
/
IntefaceRules.java
Copy path
File metadata and controls
64 lines (53 loc) · 1.67 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
package
interfaceExamples
;
public
class
IntefaceRules
{
}
interface
ExampleInterface1
{
// By default - public static final. No other modifier allowed
// value1,value2,value3,value4 all are - public static final
int
value1
=
10
;
public
int
value2
=
15
;
public
static
int
value3
=
20
;
public
static
final
int
value4
=
25
;
// private int value5 = 10;//COMPILER ERROR
// By default - public abstract. No other modifier allowed
void
method1
();
// method1 is public and abstract
// private void method6();//COMPILER ERROR!
public
static
void
m1
() {
//And we can provide definition for
//static method (From java 8 it's possible)
System
.
out
.
println
(
"Static method"
);
}
//Interface can have a default definition of method.
//NEW FEATURE
default
void
method5
() {
System
.
out
.
println
(
"Method5"
);
}
}
interface
ExampleInterface2
{
void
method2
();
}
interface
test
{
void
te
();
}
// An interface can extend another interface
// Class implementing SubInterface1 should
// implement method3 and method1(from ExampleInterface1)
interface
SubInterface1
extends
ExampleInterface1
{
void
method3
();
}
/*
* //COMPILE ERROR IF UnCommented //Interface cannot extend a Class interface
* SubInterface2 extends InterfaceRules{ void method3(); }
*/
/* A Class can implement multiple interfaces */
class
SampleImpl
implements
ExampleInterface1
,
ExampleInterface2
{
/*
* A class should implement all the methods in an interface. If either of
* method1 or method2 is commented, it would result in compilation error.
*/
public
void
method2
() {
System
.
out
.
println
(
"Sample Implementation for Method2"
);
}
public
void
method1
() {
System
.
out
.
println
(
"Sample Implementation for Method1"
);
}
}
Back
|
FazBrowse Home
|
New Git URL