Yes, you can declare a interface without any method.
Indeed, It works.
All Java books will tell you the difference, some key points:
1. Apparently, a class can implement several interfaces, while it is
not permitted to derive several abstract classes.
2. Usually, interface stands for some kind of attributes, such as
"Serializable", "Accessible". So we could say the object has such
attribute or ability
But abstract class indicates the essential property of the class, such
as "Vehicle", "Computer". So we usually say the object belongs
to ..........
3. Abstract classes can have their concrete methods, but the methods
declared in a interface are all abstract.
I don't known what exactly the question is.
For interfaces, Variable values declared will be "final" by default.
private/protected parameters are not allowed. But (public, package
scope) static final variables can be defined.
public interface Two {
final int books = 50;
}
== public interface Two {
int books = 50;
}
Q 1) Is it possible for an interface class to have no method?
The correct answer is yes: please refer to java.io.Serializable,
Cloneable interface which are marker interfaces
Q 2) Is it possible for an interface class to declare variables only
no method?
Yes: Sometimes, application wide configuration information can be
stored in interfaces and just implement the interface wherever the
information is needed.
Q 3) What is the main difference between interface and abstract
class?
Interfaces, as defined by everyone, is a contract that
implementing classes need to adhere to. As for difference between
Abstract Class/Interface, Abstract Class forms part of Object
Hierarchy (Super Class-sub class), Abstract class attributes can be
instance specific. Please refer to java.util.AbstractCollection,
java.util.AbstractList... for examples.
Q 4) Is it possible to have only abstract class without interface
Yes. You don't want to mix abstract class concepts with interfaces.
Interfaces are contract to implementing that they adhere to the method
signature, scoping, and exception handling.