Solved

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

Posted on 2004-08-26
7
201 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now