Would following sentence in short be correct for beginner to understand what interfaces are about: Interface provides methods of implementing class in abstract way without necessity to apply inheritance.
Asked
Active
Viewed 88 times
-5
-
No. Interfaces do not provide access to fields of classes. And "provide access" is not a very accurate description anyway. – khelwood Oct 23 '19 at 07:46
-
1No. Don't try to create definitions. Read existing (reliable) resources on the matter. – Stultuske Oct 23 '19 at 07:48
-
I'm not a beginner, and I don't understand your definition. If I were a beginner, I really wouldn't know where to start with that. – Dawood ibn Kareem Oct 23 '19 at 07:50
-
You can read tons of resources but without short and exact definition it is hard to understand what it is all about. Here is the definition from Sun " an interface is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. ... **When an instantiable class implements an interface, it provides a method body for each of the methods declared in the interface**". – user12246232 Oct 23 '19 at 08:53
2 Answers
1
In one sentence: An Interface is a contract for implementing classes to provide defined methods (not fields!)

Lecagy
- 489
- 2
- 10
-
OK, except access to fields, your definition is actually same as mine: implementing classes provide defined methods. Probably access is not correct word but what you finally have is a methods of implementing class. – user12246232 Oct 23 '19 at 08:11
-
I don't want get into discussion of full functional of interfaces and book descriptions but what I want to see is a short and descriptive sentence. Thank you all. – user12246232 Oct 23 '19 at 08:16
-
0
Simple definition of interface :
An interface is just like Java Class, but it only has static constants and abstract method. Java uses interface to implement multiple inheritance. A Java class can implement multiple Java Interfaces. All methods in an interface are implicitly public and abstract.
Before java 8, interface in java can only have abstract methods. All the methods of interfaces are public & abstract by default. But Java 8 allows the interfaces to have default and static methods too.

Vimal
- 411
- 6
- 28
-
1Since Java 8 Interfaces can not only contain abstract methods but can also provide `default` implementation of methods too! – Mushif Ali Nawaz Oct 23 '19 at 08:06
-
1