-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface
More file actions
executable file
·55 lines (47 loc) · 1.5 KB
/
interface
File metadata and controls
executable file
·55 lines (47 loc) · 1.5 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
- blueprint of class
- used to achieve abstraction & multiple inheritance
Syntax:
interface interface_name{
methods; // abstract,public
fields; // static,final,public
}
- only have abstract & public methods(by default)
- fields are static,final & public(by default)
- represents IS-A relationship
- cannot instantiate
- achieve loose coupling
relationships
class----->class - extends
class----->interface - implements
interface----->interface - extends
Difference
Abstract class Interface
1. abstract/non-abstract 1. only abstract methods
2. achieve partial abstraction 2. 100% abstraction
3. abstract class should extended 3. interface should be implemented using
using extends keyword implement keyword
4.fields - non-final 4. final
*********Marker Interface***************
- empty interface(no fields or methods)
- interface that does not contain any methods,fields
- tag interface
- it delivers additional info to the JVM about an object @run time
- inform the compiler by a message to add some special behaviour to object of class implementing it.
Syntax:
interface marker_interface{
}
Ex. Serializable,Cloneable,Remote Interface
instanceof - to test whether object is an instance of specified type
HomeWork:
create two marker interface - Vehicle & Engine
Create classes
use instanceof operator
class Car{
boolean isVehicle();
}
class Bike{
boolean isVehicle();
}
class Status{
isWorking();
}