answersLogoWhite

0


Best Answer

Interfaces are basically outlines. They define methods which any and all subclasses need to implement. Since an interface contains no executable code, you cannot create an instance of an interface. You need to write a class to implement the methods before you can make use of it.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

A interface defines, which method a class has to implement.

This way - if you want to call a method defined by an interface - you don't need to know the exact class type of an object, you only need to know that it implements a specific interface.

Example:

interface Printer { public voidprint(String text); } class FilePrinter implementsPrinter { public void print(String text) { //append the text to a file } } class ScreenPrinter implementsPrinter { public void print(String text) { //write the text on the screen } } class SomeClass { publicprintSomething(Printer myPrinter) { myPrinter.print("Hello"); } }

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between classes and interfaces?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

What is the difference betwen class and interface?

classes can be extended and interfaces can be implemented.


What is difference in use between interfaces and abstract classes in java?

While neither abstract classes nor interfaces can be instantiated in Java, you can implement methods in abstract classes. Interfaces can only define methods; no code beyond a method header is allowed.


What is similarities between interface and classes?

The similarities are: a. They are both java basic object types b. They both can contain variables and methods (With difference being class methods have implementation code whereas the interface methods can only have declarations) c. They can both be inherited using Inheritance (extends keyword for classes and implements keyword for interfaces)


What's the difference between Classes 375 377 and 379?

The difference between the Classes 375 377 and 379 is the services that are provided to the customer.


What is the difference between classes of IP addresses?

difference between ip address and class


What's the difference between the British Rail Classes 313 315 and 317?

The difference between the British Rail Classes 313,314 and 317 is the different locations in which they are used.


What is the most significant difference between the holdovers and animals in all other classes?

what's the most significant difference between the holdovers" and animals in all other classes. what's the answer.


Why is interfaces used in java?

Interfaces are a way of imposing a type of functionality on all other java classes that are created using it. It is kind of a template that all child classes using this template must follow. All methods that are declared in an interface must be implemented by the child classes and hence the functionality offered by these classes can be controlled using them. Interfaces are a powerful tool that java provides to achieve multiple inheritance.


What is the package and interfaces?

Package:- package is collection of related classes and interfaces which can be import in our program. There are different built in packages available in java.Package provide us a facility to create user define packages. Interfaces:- Interface is just like abstract class but the difference is that we can implements any no of interfaces in a single class .It is an alternative solution for multiple inheritance which is not available in java. Once we have implement the interface we can define methods of that interface in our class.


How can you design package in java?

it's a collection of classes is called a package .its a collection classes and interfaces which provides high level of security


What is the important?

Import statements are used to reference classes and interfaces declared in other packages.


What is Difference between C structers and classes?

through classes we can create objects and we can implemented businessmathods. in case of structres we can create streuctre variables but not methods this is the major difference