describe interfaces in java langaugeinterfaces


Describe Interfaces in java langauge?

Interfaces are the further level of abstraction. An interface is like a class along with nothing but abstract methods and final, static fields. All methods and fields of an interface must be public.

Therefore, unlike a class, an interface can be added to a class which is already a subclass of another class. In addition an interface can apply to members of several different classes. For example you can define an Import interface with the single techniques calculateTariff().

public interface Import {

public double calculateTariff();

}

You might need to use this interface on several different classes, cars between them but also for clothes, food, electronics and more. It would be inconvenient to form all these objects derive from a single class. Additionally, each different kinds of item is likely to have a different means of calculating the tariff. Thus you define an Import interface and declare in which each class implements Import.

The syntax is easy. Import is declared public so in which it can be accessed from any class. It is also probable to declare that an interface is protected so that it can only be implemented by classes in a particular package. However this is extremely unusual. Almost all interfaces will be public. No interface may be private because the whole purpose of an Interface is to be inherited through other classes.

The interface keyword takes the place of the class keyword. Line 3 looks such as a classic method definition. It's public (as it must be). It's abstract, also as it must be. And it returns a double. The method's name is calculateTariff() and it takes no arguments. The difference among this method and a method in a class is that there is no method body. That remains to be created in each class in which implements the interface.

You can declare several different methods in an interface. These methods may be overloaded. An interface can also have fields, but if so they must be final and static (in other words constants).

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: describe interfaces in java langaugeinterfaces
Reference No:- TGS0284831

Expected delivery within 24 Hours