Skip to content

Commit 7ad3588

Browse files
committed
added files
1 parent 3a129c6 commit 7ad3588

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Interface.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import java.util.*;
2+
3+
// Understanding the interface concept.
4+
// An interface is a reference type in Java. It is similar to class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
5+
// Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods.
6+
// Writing an interface is similar to writing a class. But a class describes the attributes and behaviors of an object. And an interface contains behaviors that a class implements.
7+
// Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.
8+
9+
interface Person {
10+
void displayDetails();
11+
boolean works();
12+
}
13+
14+
class Student implements Person {
15+
String name;
16+
int age;
17+
String course;
18+
19+
Student(String name, int age, String course) {
20+
this.name = name;
21+
this.age = age;
22+
this.course = course;
23+
}
24+
25+
public void displayDetails() {
26+
System.out.println("Name: "+name+" Age: "+age+" Course: "+course);
27+
}
28+
29+
public boolean works() {
30+
return false;
31+
}
32+
}
33+
34+
public class Interface {
35+
public static void main(String[] args) {
36+
Student student = new Student("John", 20, "Computer Science");
37+
student.displayDetails();
38+
System.out.println("Does student work? "+student.works());
39+
}
40+
}

0 commit comments

Comments
 (0)