Describe interfaces in java langauge, JAVA Programming

Assignment Help:

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).


Related Discussions:- Describe interfaces in java langauge

Differentiation between if statement and a switch statement, Differentiatio...

Differentiation between if statement and a switch statement ?

What is aop alliance, AOP Alliance is an open-source project whose goal is ...

AOP Alliance is an open-source project whose goal is to promote adoption of AOP and interoperability between different AOP implementations by describing a common set of interfaces

How is method overriding different from method overloading, How is method o...

How is method overriding different from method overloading? Overriding involves the creation of two or more concepts with the same name and same signature in different classes

Give an examples of access protection, Give an Examples of Access Protectio...

Give an Examples of Access Protection ? This is how the Car class would almost certainly be written in practice. Remember that all the fields are now declared private, and the

What are application softwares, What are application softwares? List down t...

What are application softwares? List down the names of three application software's. Definition: Application Software are in which software then can interact directory along

Write a cgi program, Write a CGI program in R, accessible through the class...

Write a CGI program in R, accessible through the class web server, that performs an analysis or creates a graph. You can provide a separate HTML page that displays the initial form

Use the constructor, Can we use the constructor, instead of init(), to init...

Can we use the constructor, instead of init(), to initialize servlet? Ans) Yes. Of course you can use the constructor instead of init(). There's nothing to stop you. But you sho

What is dispatchaction, The DispatchAction class is used to group related a...

The DispatchAction class is used to group related actions into single class. Using this class, you can have a method for every logical action compared than a one executes method. T

Application to upload dicom files from cd to dropbox, Application or websit...

Application or website to upload DICOM files from CD to Drop box etc Project Description: I need a website code or application to make patients put a cd or DVD to their disk

What is preferred organizational structure for organization, What is the pr...

What is the preferred organizational structure for the organization? The Network Organization is becoming the preferred organizational structure.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd