Solved

Interface (Java) & Abstract Class (C++) ?

Posted on 2004-08-26
7
219 Views
Last Modified: 2012-05-05

 Hi Experts,

    This is actually a follow up question of :
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21107718.html

  Now I have more idea about interface. Then I am wondering does the "interface" in Java play the same role as the "abstract class" in C++ ?

  Is it true that : " The are multiple (class) inherence in C++, but java can extend only one class. Therefore, the interface actually doing something like "multiple inherence" in C++" ?

   Thanks a lot !!!

 meow.
0
Comment
Question by:meow00
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
Javatm earned 150 total points
ID: 11909432
Hi Friend;

The answer to this question that you posted and also this one that you posted :
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21109221.html

Is in here : http://www.firstsql.com/java/gotchas/

=-) Read that and that should answer your questions !.

Glad to help . . .
Javatm
0
 
LVL 15

Expert Comment

by:Javatm
ID: 11909464
>  Then I am wondering does the "interface" in Java play the same role as the "abstract class" in C++ ?

Answer = True;

> The are multiple (class) inherence in C++, but java can extend only one class.
> Therefore, the interface actually doing something like "multiple inherence" in C++    

Answer = True;

Read the links above for further explanations !

Hope that helps . . .
Javatm    
0
 
LVL 35

Assisted Solution

by:girionis
girionis earned 100 total points
ID: 11910306
>  " The are multiple (class) inherence in C++, but java can extend only one class. Therefore, the
> interface actually doing something like "multiple inherence" in C++" ?

You could say that although this is not strictly true. The point of inheritance is to inherit characteristics from the parent class, i.e. bahaviour or state. An interface does not implement any behaviour (although it can have state through its variables) so you must be very careful when you use the term "multiple inheritance" by using interfaces. A better term would be "multipel interfaces inheritance"

You might also want to take a look here:

http://mindprod.com/jgloss/multipleinheritance.html
http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html
http://www.javaworld.com/javaworld/jw-04-2001/jw-0413-polymorph.html
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 12

Assisted Solution

by:Giant2
Giant2 earned 50 total points
ID: 11910506
Interface in Java tell "only" what the classes implementing this interface must implement.
The intent of abstract class is to provide general functionality (taken from MSDN).

Interface in java do not specify any piece of code. It contains the declaration of the methods.
If you want a similarity with C, you can find in some manner about java interface and declaration of the method in C.

And abstract in C is little similar to abstract in java.

Hope this clarify some doubt, Giant.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11912297
:)
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11912316
Thanks.
:)
0
 
LVL 15

Expert Comment

by:Javatm
ID: 11917755
=-) Always glad to help . . .

http://freewebs.com/cube-j
Friend : Javatm
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question