answersLogoWhite

0

Why do you use interfaces instead of class?

Updated: 8/19/2019
User Avatar

Wiki User

13y ago

Best Answer

JAVA does not support multiple inheritance(i.e more than one class cant be inherited by other classes.) but multiple inheritance is a very important concept . For this reason interface is used which is a kind of class but he difference is that it contains only constant variables and abstract methods. abstract methods contains only the declaration not the codes.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why do you use interfaces instead of class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you choose a Windows or Mac desktop display when you use the Linux operating system?

No. Those user interfaces are copyrighted. However, some distros have fairly similar interfaces that you can use instead.


What is the minimum number of interfaces that a java class can have?

Zero. By default they do not implement any interfaces.


Why you use class libraries in dot net?

cause The .NET Framework class library is a library of classes, interfaces, and value types that provide access to system functionality


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.


What is the difference betwen class and interface?

classes can be extended and interfaces can be implemented.


How do you achieve multiple inheritence using class in java?

Multiple Inheritance cannot be achieved only by using Classes in Java. You would have to use Interfaces as well to achieve multiple Inheritance. Java as such does not support direct multiple inheritance. We can have theoretical multiple inheritance by using interfaces using which you can outline the kind of functionality your child classes can have. For example you can have a declaration like this public class A implements X, Y, Z { } Here this class A would have to implement the methods that are declared in the interfaces X, Y & Z. So the outline of the functionality that A would have can be found by checking the interfaces but the exact implementation would depend on the programmer who codes class 'A'


Interface is used in java but not in C why?

The short answer: because C is not object-oriented. The reason for C++ not having interfaces is, that C++ supports multiple inheritance. Because C++ classes can be derived from more than one base class, so there is no need to have interfaces. In Java, each class has exactly one base class (except the class Object). With the help of interfaces it is possible implement a restricted (and more stable) form of multiple inheritance. Interfaces follow implicitly the following rules: * interfaces are abstract * each method is public abstract * each attribute is public static final


What are the alternatives to inheritence in java?

Java does not support multiple inheritance; a subclass cannot have more than one parent. Java compensates for this with interfaces. A class can implement multiple interfaces, but can only extend one class.


Can you use multiple inheritance in .NET?

Multiple inheritance in C# In C#, the classes are only allowed to inherit from a single parent class, which is called single inheritance. But you can use interfaces or a combination of one class and interface(s), where interface(s) should be followed by class name in the signature.


How do you achieve multiple inheritance?

Any class can extend one class and/or implement multiple interfaces. For example: public class TestClass extends SuperTestClass implements InterfaceA, InterfaceB { // implementations of interface methods in here }


What is non-instantiable class?

A non-instantiable class is the class whose object can be created but cannot be initialized. for example the interfaces and the abstract classes in java.


Give the structure of multiple inheritance?

Java does not support multiple inheritance. It is done with the help of interfaces in java. a class can implement n number of interfaces, thus showing multiple inheritance. but a class cannot extend multiple classes in java.