Confused about Java and Interface

StormRider

Diamond Member
Mar 12, 2000
8,324
2
0
I'm learning Java on my own right now and one of the things I read is that Java follows the single inheritance paradigm of object oriented programming while C++ allows multiple inheritance.

But Java has something called the Interface which (to me) looks exactly like multiple inheritance. I don't see any difference so why not just make Java be multiple inheritance? Why make up a new term like Interface which just seems like a kludge to allow multiple inheritance?

Also, I find the Java GUI stuff (Swing, AWT) to be a little cumbersome.
 

Juniper

Platinum Member
Nov 7, 2001
2,025
1
0
errr, if I remember correctly, the purpose of interfaces is to regroup the method headers, therefore easier for other programmers to make use of your classes. I think there are a couple of other reasons also, but I cannot recall them ;)
 

Jzero

Lifer
Oct 10, 1999
18,834
1
0
Interfaces aren't designed to allow multiple inheritance. The purpose of an interface is to provide for a standardized set of methods, but allow the specifics to be defined furhter down the line. It's kinda like having a device driver....
Like the OS recognizes specific commands such as open, read and write, but each devices handles those commands differently. The device driver implements the OS's i/o interface the way the device needs it to work.

That might be a pretty coarse analogy.

Anyway, as a cute side-effect, it does allow you to do ghetto double-inheritance...