-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.java
More file actions
80 lines (60 loc) · 3 KB
/
Interface.java
File metadata and controls
80 lines (60 loc) · 3 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
75
76
77
78
79
80
/*
Copyright (c) 2017-2018 Navjot Singh Virk (Website: https://navsingh.org.uk),
(Project Git: https://github.com/virksaabnavjot/jcode)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
*Interface.java
*Purpose: To learn to use interface in java and understand the meaning of it.
*Date: 13/August/2017 | Sunday | 00:22 am (Dublin,Ireland)
*/
/*Explanation: What is Interface ? Why use it? How to make use of it ? How to implement it?
http://tutorials.jenkov.com/java/interfaces.html
(Hindi) https://www.youtube.com/watch?v=P1qhuqY2HxE&t=836s
Interface (meaning - interact with )
1-Interface just specify the method declaration (implicitly public and abstract)
Example: public void greetings();
2-We dont really have to write the "public" keyword as all the methods of
an interface are public by default.
Example: void greetings(); is also correct.
3-Interface can only contain fields which are (implicitly public static final)
Example: public static final String name = "Navjot";
or
String name = "Navjot"; is also correct and its (public static and final by default
so, we dont really need to write these).
4- An Interface like an abstract class cannot be instantiated (meaning we cant create
objects of an interface).
5- An Interface do not have a constructor (as we cant create object what do we need
constructor for?).
6- If a class that implements an interface doesn't implement/define all the methods
of that interface, then that class must be declared as an abstract class and method
declerations must be provided by the subclasses that extent the abstract class.
*/
public interface Interface{
/*Variables - Syntax: dataType variableName = value;
(both the variables below are public, static and final by default either
we write public static final or not)
*/
public static final String firstName = "Navjot";
String lastName = "Singh";
/*Methods - Syntax: returnType methodName(parameters);
methods are abstract and public by default no matter we add public or not its
the same thing.
*/
public void greetings();
int guessAge(int age);
}