Domanda

Recently, I was reading the source codes of Universal-Image-Loader, And I found an interesting question on inheritance in Java. We know that the multiple inheritance is not allowed in Java. Java designers replaced the concept of multiple inheritance by that of interface. In the release 1.9.1 of Universal-Image-Loader, the interface called BlockingDeque in the package of com.nostra13.universalimageloader.core.assist.deque extends two parent class, BlockingQueue and Deque, but Eclipse does't show any wrong information about it. So I am confused about it. Does someone else ever notice this?? and the pic showing this question is below: single inheritance in Java

È stato utile?

Soluzione 2

Yeah, just like a question in my mind: doesn't Java support multiple inheritance? The fact is YES. Java refuse the multiple inheritance from classes, but it does support multiple inheritance from Interface. More exactly, both class and interface are object. "Everything is an Object".

Altri suggerimenti

nothing wrong with this code... Interface can extends Multiple Interface

public interface My extends My1,My2{

}
interface My1{
int i=10;
}
interface My2{
int met(int a);
}

Some Points You Should KNOW

1) All variables Declared in interface are by default public static

2) If I want to use Members like Methods or variable I just need to implement My interface in above case by doing this i can also get access to My1 and My2.

My ob=new ClassImplementedMy();
ob.i;

3) Moreover if i have implemented My and it extends My1 and My2 so i need to implement all the methods which are not in My but in My1 and My2.

In above example i have to state method which is in My2 when i have implemented My only.

Read this page info for more details... Click Here

Just like answers offered above, a class extends only one parent class, but implements multiple interfaces, meanwhile, an interface extends multiple interfaces but doesn't implement any interfaces. Additionally, the default access modifiers of member variables of an interface are "public static final" while that of member functions are "public abstract". And a class has to implement functions defined by the interface which is implemented by the class but the class doesn't have to implement abstract functions defined by the parent class which is extended by the class. We can get through the checking from compilers via declaring the class "abstract".

And this question is resolved. The link is here: https://github.com/nostra13/Android-Universal-Image-Loader/issues/569

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top