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

What is mvc, Model-View-Controller (MVC) is a design pattern put together t...

Model-View-Controller (MVC) is a design pattern put together to help control change. MVC decouples interface from business logic and data. ? Model: The model having the core of

Retrieving data from Excel file , how to retrieve data from Excel file, and...

how to retrieve data from Excel file, and display that data in table on jsp page?

Create a new project in eclipse , Task 1 Create a new project in Eclips...

Task 1 Create a new project in Eclipse called Assignment 1. Within this project create a package called task01. 1/ Download the class Date (you must use this class - no

How many kinds of errors can be found during a program, How many kinds of e...

How many kinds of errors can be found during a program development? List them. 1. Syntax errors 2. Semantic errors 3. Run-time errors

How many iterations would this for loop run for, How many iterations would ...

How many iterations would this ‘for' loop run for? for ( x = 50 ; x document.write ( x ) ; } Answer: 50 iterations

Define array, Define Array ? Indexed collections of variable of similar...

Define Array ? Indexed collections of variable of similar data types or we can say a Set of organized variables of similar type.

Why do we need wrapper classes, Why do we need wrapper classes? It is s...

Why do we need wrapper classes? It is sometimes simpler to deal with primitives as objects. Moreover most of the collection classes keep objects and not primitive data types. A

How to write exception subclasses, How to Write Exception Subclasses ? ...

How to Write Exception Subclasses ? Most exception subclasses inherit all their functionality from the superclass. Each subclass majorly serves as a marker for a various types

Train ticket, Write a program that manages a list of train tickets, JAVA Pr...

Write a program that manages a list of train tickets, JAVA Programming

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