answersLogoWhite

0


Best Answer

A class can inherit as many interfaces as it needs, using multiple-inheritance. And yes, the same interface can be inherited by two different classes.

Multiple inheritance occurs when a class is derived from two or more base classes. For instance, if you have a list class and a node class, then you could easily inherit from both to produce a tree class, since a tree is both a list and a node. The tree therefore inherits the interface of both a list and node and combines them into a single entity.

Just as a square and a circle are types of shape, a circle class and a square class can both inherit from the same generic shape class. Since both the circle and the square have a common interface, collections of shapes are possible, regardless of their actual type. Taxonomy is another example of this. Cats and dogs and bats are all types of mammal, thus they can all share a common interface provided by a mammal class. By the same token, mammals, reptiles and birds can share a common interface provided by an animal class. Moreover, trees, flowers and other vegetation share a common interface with animals: the class of living things. How accurately your classes reflect reality is entirely up to you: if you wish to model a dog kennel, then a common dog class is all you need to provide the base class for all dogs.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How many interfaces can a class inherit and can same interface be inherited by two different classes explain?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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.


Why can not define private and protected modifiers for variables in interface?

No. Interface variables are supposed to be public static final. Interfaces, like abstract classes, cannot be instantiated, so all variables in an interface must be static final ones. They are public because usually interfaces are used throughout an application, and this will ensure versatility.


What is markable interface in java?

The Interface which doesn't have any declarations of methods are called the markable interface (or marker interface)They are named marker interfaces, because their only purpose is to mark special classes.Example:In the Java API there is the interface Cloneable. Since Object already has the method clone() the Cloneable Interface is empty and is only used to mark classes, which objects are allowed to clone.There are Three marker interfaces that are Serializable,Remote and Cloneable.


Interface in C plus plus?

Unless by "interface" you mean a user interface...C++ does not have interfaces per se, at least not in the same sense as, say, Java. In a C++ class, a function declared pure virtual makes the class non-instantiable and forces derived classes that want to be instantiable to provide an implementation. This has exactly the same effect as the interface concept of Java. So in C++, interface is just a synonym for abstract base class.


Which languages support multiple interface?

If by interface you mean, a mechanism to achieve abstraction and create a blueprint for future implementation. Java/C#/C++ all allow for multiple interfaces(abstract classes in C++) to be implemented.

Related questions

What is the difference betwen class and interface?

classes can be extended and interfaces can be implemented.


In the field of computers what does the term java interface mean?

In Java, an interface is a suite of methods that multiple different classes are able to implement. Interfaces are not assigned to any particular class. For example, multiple graphics classes can use the same interface to change their size and colour.


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


Is a inference a type of variable?

No an Interface is a type of class that is designed to support partial multiple inheritance in Java. Interfaces are used to create skeleton classes that can direct the functionality of all classes that implement them. Interfaces have only method declarations and the class that implements the interface must provide the implementations for them


When to use interface?

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.


Why can not define private and protected modifiers for variables in interface?

No. Interface variables are supposed to be public static final. Interfaces, like abstract classes, cannot be instantiated, so all variables in an interface must be static final ones. They are public because usually interfaces are used throughout an application, and this will ensure versatility.


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 markable interface in java?

The Interface which doesn't have any declarations of methods are called the markable interface (or marker interface)They are named marker interfaces, because their only purpose is to mark special classes.Example:In the Java API there is the interface Cloneable. Since Object already has the method clone() the Cloneable Interface is empty and is only used to mark classes, which objects are allowed to clone.There are Three marker interfaces that are Serializable,Remote and Cloneable.


When to use interfaces and when to use abstract classes?

just one word supscription interface means mediater abstract means data hiding


Interface in C plus plus?

Unless by "interface" you mean a user interface...C++ does not have interfaces per se, at least not in the same sense as, say, Java. In a C++ class, a function declared pure virtual makes the class non-instantiable and forces derived classes that want to be instantiable to provide an implementation. This has exactly the same effect as the interface concept of Java. So in C++, interface is just a synonym for abstract base class.