The Artima Developer Community
Sponsored Link

Java Answers Forum
abstract classes

1 reply on 1 page. Most recent reply: Mar 25, 2002 1:47 PM by Junk Mailer

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
nimmi

Posts: 1
Nickname: puppy
Registered: Mar, 2002

abstract classes Posted: Mar 23, 2002 11:06 PM
Reply to this message Reply
Advertisement
what is the difference between abstract classes in C++ and java interfaces


Junk Mailer

Posts: 1
Nickname: junkmailer
Registered: Mar, 2002

Re: abstract classes Posted: Mar 25, 2002 1:47 PM
Reply to this message Reply
I can think of a few of the top of my head...

1/ In C++, for a class to be abstract, at least one method needs to to a pure virtual method. So what that means is the class can potentially contain other methods that are not pure virtual methods.

In case of interfaces in Java, all methods are abstract.

2/ In C++, the abstract class can contain default implementation of the some of the methods.

In Java, the interface class can not contain any implementation.

3/ In C++, the abstract class can contain, attributes.
In Java, the interface class can not contain any attributes.

4/ In C++, when a class inherits from an abstract base class, the child class NEED not implement all of the pure virtual methods defined in the base class. Of ocurse, if all of the pure virtual methods are not implemented some where in the hierarchy then the class will continue to be abstract and cannot be instantiated.

In Java, when an interface is implemented by a class, ALL of the methods in the interface need to be implemented by the class.

These were just some of the differences I could think of. In retrospect abstract class in C++ are more similar to abstract classes, than interfaces, in Java.

Hope that helped.

Flat View: This topic has 1 reply on 1 page
Topic: mobile+Java Previous Topic   Next Topic Topic: how do you verify a password?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use