What's the difference between Abstract Class and Interface?

Dear all,
Can anyone give me some hints about this topic?
Thanks.
Leo

an abstract class may have some methods already implemented in the abstract class but an interface has no methods implemented
I think it's just that simple.
For your design needs, you just choose what you need : )
Cheers
Stephen

Similar Messages

  • What is the difference between Abstract class and Interface ?

    Hi,
    Could u plz tell me the difference between Abstract class and Interface?
    Thanks in advance.
    Gopi

    Lots.
    An abstract class can contain some method implementations, or indeed all the method implementations. It may contain methods with all the various access modifiers. It cannot be instantiated. A class may inherit from only a single abstract class.
    An interface contains only public method stubs and constants. A class may implement multiple interfaces. An interface cannot (obviously) be instantiated.
    Abstract classes are particularly useful when you need to provide a semi-complete implementation for reuse. Interfaces are used more like types.
    Look at java.util.* for some good examples of the use of both.

  • Difference between abstract classes and interfaces

    I actually wonder about what are the differences between abstract classes and interfaces may somebody give an example code about it?
    and i have one more question how can i use interfaces like multiple inheritance ? i mean when i implement an interface like
    class a extends b implements c,di have to use all c and d methods but what that methods means?
    I mean as i know we cannot make implementations of methods in interfaces
    but for example in runnable interface there is a method like run() and it has been defined somewhere because it knows what to do(i mean when it will run), i just write my code into that method .

    Once you get past the starting point (I am referring to the OP here), there are a few salient differences:
    You can only extend (or generalize) a single superclass; however, you can implement (or realize) multiple interfaces. As such, all things being equal, using an interface in lieu of an abstract class 'frees' your design. Later, if you want the implementor of an interface to inherit from another class, there is not issue.
    Any abstract method specifies a contract. However, abstract classes allow you to also add common behavior to subclasses. This is an overused justification for abstract classes, IMO. You can achieve the same effect using delegation and still having interfaces.
    Always program to interfaces wherever possible. This means that you define an interface and have an implementing class (usually at a minimum). Do not do this for all your classes, but rather the ones that make your system unique (the domain model or M in MVC architecture). This allows you to later change implementation with a minimal amount of refactoring. This is a core precept from the Group of Four and any number of decent programming books.Best of luck.
    - Saish

  • What is the difference between document class and normal class

    Hi,
    Please let me know what is the difference between document class and normal class.
    And I have no idea which class should call as document class or call as an object.
    Thanks
    -Actionscript Developer

    the document class is invoked immediately when your swf opens.  the document class must subclass the sprite or movieclip class.
    all other classes are invoked explicitly with code and need not subclass any other class.

  • What is the difference between div class and div id

    I have managed to achieve a two colum css within my content.  I normally use "div id" but when I did my two colums it only worked (for me anyway) if the content was a "class" and the right content a "div".  Why is this? Is this incorrect?
    This is my code
    .content {
              height: 400px;
              width: 300px;
              background-color: #FF0;
              float: left;
    #rightcontent {
              width: 694px;
              background-color: #0FF;
              float: right;
              height: 400px;
    If I try to have content as "id" it disapears.
    Thank you in anticipation.  Karen

    If I change the div class to id, then my box on the left hand side disappears.  This is the code below.  I set the page up like that as it's more of a banner so I can have my promotions at the top of my page, so no I guess I should not have used "content"..  Then I was going to have a content area and then a footer for my links to pages.
    <div class ="content">
    <p>Our Fantastic New Design</p>
    </div>
    <div id="rightcontent"></div>
    </div>
    </body>
    </html>
    New question - I want to copy my header and dropdown menu on all of my other pages, I was practicing last night but it did not work.
    I linked the dropdown menu css to a new page, but I did not link the css styles as I dont want all of my pages being the same.  Originally I just copied one page to another, that's when I found out that if I changed one page then it changed the other, does that mean I need to set up all new css styles for each page?
    below is what I copied to create the header and dropdown menu on each page.
    <div class="container">
      <div class="header"></div>
    <div id="wrapper">
    <div id="navMenu">
    <ul>
    <li><a href="#">Home</a>
    <ul>
    <li><a href="#">link item</a></li>
    <li><a href="#">link item</a></li>
    <li><a href="#">link item</a></li>
    <li><a href="#">link item</a></li>
    <li><a href="#">link item</a></li>
        </ul> <!end inner ul-->
    </li> <!end li-->
    </ul> <!end main ul-->
    <br class="clearFloat" />
    </div> <!end navMenu->
    </div> <!end wrapper->
    I obviously copied all of my links! 
    www.bristolequestrianservices.co.uk

  • Difference between abstract class and interface

    Hi everyone,
    CAn anyone explain why the following happen????
    Abstract class can have a constructor, Interface cannot.
    Abstract class can have static methods, Interface cannot.

    What are the advantages of defining constant
    variables in Interfaces?Not many.
    Effective Java - Joshua Bloch, Chapter 4, Item #17: Use interfaces only to define types.
    The constant interface pattern is a poor use of interfaces. That a class uses some constants internally is an implementation detail. Implementing a constant interface causes this implementation detail to leak into the class's exported API. It is of no consequence to the users of a class that the class implements a constant interface. In fact, it may even confuse them. Worse, it represents a commitment: if in a future release the class is modified so that it no longer needs to use the constants, it still must implement the interface to ensure binary compatibility. If a nonfinal class implements a constant interface, all of its subclasses will have their namespaces polluted by the constants in the interface.
    In summary, interfaces should only be used to define types. They should not be used to export constants.

  • Difference between Abstract Classes Vs Interface

    Hi,
    Can u pls mention all the differences between Abstract Classes and Interface.? I've mentioned the differences I've known here.
    Known Differences:
    (*) An interface cannot implement any methods, whereas an abstract class can.
    (*) A class can implement many interfaces but can have only one superclass
    Can U pls mention at what situation(practical situation) we've to go for abstract class or Interface?
    Tell me the situation when we have to go for abstract class?
    Tell me the situation when we have to go for interface?
    Please Reply me
    Thanks & Regards
    Venkatesh

    There are more differences, and one really important is that abstract classes can also define class variables, while interfaces cannot. I think the question of when to use interfaces or abstract classes is not always easy to answer, but yourself have pointed some tips you should be aware of :
    If you need that some funcionality of the class is derived by more than one "parent" then you should use interfaces, since you cannot extend more than one class.
    If your "superclass" needs to define some class variables then the choice must be made to have a superclass and then extend it. Also this is applicable if there is a method that can be programmed at a higher level (in interfaces you cannot program methods).
    But the answer to the question is still not easy. And remember, you can always mix both tipes, you can extend one class and implement some interfaces.
    Examples or that are very common in the Java API for AWT or Swing components, for example javax.swing.JLabel extends javax.swing.JComponent (that is beacuse a JLabel IS a JComponent and it uses some variables and methods programmed at the JComponent "level") and it also implements some interfaces: Accessible, ImageObserver, MenuContainer, Serializable & SwingConstants.
    I hope this helps.
    Zerjillo

  • Difference between Abstarct Class and Interface

    HI,
    Here is a simple one for the gurus but quite important for me.
    What is the difference b/w an Interface and an abstract class?
    Why do we need each one of them?
    I would appreciate if you people can give examples of each so that I amy understand fully
    Thanks in advance...

    A normal class (not abstract) has a special behaviour, like java.awt.Frame. A Frame is a frame no matter how you subclass it. If you create a subclass it will still be able to be displayed by calling it's show method. So by using a normal class you can create a type of class.
    An abstract class does the same, but it leaves some of the code unwritten. For instance java.lang.Number. This class is abstract becuase it has no knowledge of how to store the number in memory. But it knows that it is a number, and any subclass will still be a number. You could create a subclass of Number that can hold the time in milliseconds and checks your system clock to see what the time is, it could also have methods that return the time in another country, but it would still be just a Number.
    An interface is a way to describe what an object can do, not what it is. So with java.lang.Comparable as an example you can make any class comparable. This means that no matter what type of object you have, it can be compared with other objects. So you can have a subclass of Frame that can be compared with other windows. Or a subclass of Number that can be compared with other Numbers. You can even compare those two different types if you like. So you could compare a window with a number.
    That is the difference between abstract classes and interfaces.
    I hope you could follow my arguments, it isn't an easy subject,
    Daniel

  • What's the difference between batch class type 022 and 023?

    Hi Guys,
    I find that some of my SAP client only have class 022 and some have 023, but no client has  them all. I don't know why it happed.
    So what's the difference between batch class type 022 and 023?  Which setting decide which class to be used ?
    Thanks.

    Hi nitin,
    Read  http://www.sapfans.com/forums/viewtopic.php?t=212819&highlight=022  you will know the difference between 022 and 023 .
    Use tcode OMCT you can switch batch level .

  • What is the difference between access specifiers and access modifiers?

    what is the difference between access specifiers and access modifiers? are they same? if not what is the difference.

    Access Specifier are used to specifiy how the member variable ,methods or class to other classes.They are public ,private and protected.
    Access Modifier:
    1.Access
    2.Non Access
    Access:
    public ,private,protected and default.
    Non Access:
    abstract,final,native,static,synchronized,transient,volatile and strictfp

  • What is the difference between jsp :include and server side include

    what is the difference between jsp :include and server side include(request dispatcher include method)????
    i understand that both request dispatcher include method and jsp:include take dynamic data,so when would one use request dispatcher include and when jsp:include.
    Is the usage interchangeable?i believe jsp include is used only for jsp/html but include directive can be used to include servlets ,jsp and html....correct me if i m wrong and
    do suggest if u hav ny other diff in this context...

    The difference really is: in what format do you want your inclusions? If your environment has many Java developers and only a few designers that focus mainly on, say, Flash, that might push you more towards the server-side include() directive. Or, if you have a large set of pages that receive dynamic content that is displayed in a consistent fashion (such as a workflow header area on a page).
    If, on the other hand, you have more web designers, there may be a greater desire to deal in markup rather than Java code. Java developers themselves might prefer to view markup (JSP) that more resembles the eventual output than something occuring in Java code.
    Finally, there are considerations of tiering. While it is totally possible to (and I have previously) implement 'view classes' that render markup or generate layout templates, JSP's offer, IMO, a subtle, psychological advantage. By forcing a developer to work in a different format, markup versus Java source, the separation on view from controller and model becomes a bit easier. It is still possible to make mistakes, but if a developer at some point notices, "Wait, I'm in a JSP, should I be importing a java.sql class?", then the choice to use JSP includes has paid off in spades.
    - Saish

  • What is the difference between Business System and Business Service?

    Hi
    Please tell me what is the difference between Business System and Business Service...? In real time at what situation we will use Business System and in what situations we will use Business Service..? Please help me
    Best Regards
    Ravi Shankar B

    HI,
    Business system:
    If you want to address a particular business system as the sender or receiver of messages, choose this service type.
    A business system is an actual application system in a system landscape. A business system (service) comprises information about the inbound and outbound interfaces and the software component versions of the business system.
    You usually use business system services when configuring internal company processes.
    Business Service:
    If you want to address an abstract business entity as the sender or receiver of messages, choose this service type.
    Using a business service, you can define the technical or business subunits of the companies involved and then assign them the relevant interfaces.
    You usually use business services when configuring cross-company processes. In this case, you only make your interfaces known to the business partners involved and either do not make any details about your own system landscape available, or only specific details. 
    For example, you can define RosettaNet Partner Interface Processes (PIPs) as business services.
    Regards,
    Sudheer.

  • What is the difference between Instance variable and Global variable?

    Hi folks,
    Could you please explain me, "what is the difference between Instance variable and Global variable?"
    Are they really same or not?
    --Subbu                                                                                                                                                                                                                                                                                                               

    Hi flounder,
    I too know that there is no such a term GLOBAL in java.
    generally people use to say a variable which is accessible throught out the class or file has global access
    and that will be called as a global variable...
    my point is very much similar to what Looce said.
    In simple that is not a technical term, but just a causual term.
    In technically my question is, "What is the difference between a instance variable and public variable?".
    Hi looce,
    Thanks for the reply. even thats what my understanding too....in order to confirm that i raised this question..
    Your reply has given a clear answer...... thanks again.
    --Subbu                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • What is the difference between Topic Keywords and Index File Keywords?

    What is the difference between Topic Keywords and Index File Keywords? Any advantages to using one over the other? Do they appear differently in the generated index?
    RH9.0.2.271
    I'm using Webhelp

    Hi there
    When you create a RoboHelp project you end up with many different ancillary files that are used to store different bits of information. Many of these files bear the name you assigned to the project at the time you created it. The index file has the project name and it ends with a .HHK file extension. (HHK meaning HTML Help Keywords)
    Generally, unless you change RoboHelp's settings, you add keywords to this file and associate topics to the keywords via the Index pod. At the time you compile a CHM or generate other types of output, the file is consulted and the index is built.
    As I said earlier, the default is to add keywords to the Index file until you configure RoboHelp to add the keywords to the topics themselves. Once you change this, any keyword added will become a META tag in the topic code. If your keyword is BOFFO, the META tag would look like this:
    <meta name="MS-HKWD" content="BOFFO" />
    When the help is compiled or generated, the Index (.HHK) file is consulted as normal, but any topics containing keywords added in this manner are also added to the Index you end up with. From the appearance perspective, the end user woudn't know the difference or be able to tell. Heck, if all you ever did was interact with the Index pod, you, as an author wouldn't know either. Well, other than the fact that the icons appear differently.
    Operationally, keywords added to the topics themselves may hold an advantage in that if you were to import these topics into other projects, the Index keywords would already be present.
    Hopefully this helps... Rick

  • What is the difference between Video-out and mirroring?

    What is the difference between Video-out and mirroring? I can't get iPhone 4 video to work on my TV screen
    I have just bought an MD098ZM/A (Apple 30-pin Digital AV Adapter). I am struggling to get it to show a picture on my TV. I know I'm doing something right because the audio is coming out of my TV speakers but no picture on the TV screen.
    I have used the same HDMI channel (on the TV side) with the same cable and my thunderbolt port (MacBook Air) without any trouble - and on the same app (BBC iPlayer download then full-screen mode).
    Now I note that the packaging for the MD098ZM/A says video-out on iPhone 4 but mirroring only on iPhone 4S. I only have an iPhone 4 (not the 4S). Now if the lack of iPhone 4 support for mirroring means that I can't play video material out to my TV, then in what sense is there any video-out capability at all?
    There is only safety and warranty paperwork in the Apple adapter packaging - no help information. And I haven't found further guidance online either.
    I do note somewhere online that it suggests that basic non-mirroring video-out (for this adapter) only works with some external TV sets. Any way of finding out which? I'm using a Sanyo CE32LD90-B LCD TV if it helps.
    So far not doing very well.

    Now found these but have had to give up on this adapter!
    http://manuals.info.apple.com/en_US/iphone_user_guide.pdf
    http://support.apple.com/kb/HT4108

Maybe you are looking for

  • How can I re-install OS X on a PowerBook when the DVD drive is dead?

    I'm trying to reload my operating system on a PowerBook with the disk drive dead. I've tried starting the the laptop as a target disk and plugging it into my Mac Pro and using the disk drive from the Mac Pro. It loads everything on the PowerBook fine

  • Batch change page size of InDesign documents

    I have about 300 one-page InDesign (cc 2014, Mavericks) documents of varying page sizes. Each page is 4 inches wider and 4 inches taller that the content of the page. The content is in the middle of the page-effectively making a 2-inch margin (but wi

  • Financial Reporting Chart - Waterfall or Step Chart or 2 Y-Axis chart?

    Using Hyperion Financial Reports 9.3.1.2 - How do you create a waterfall or step chart using a stacked bar chart in FR chart? I have created a waterfall or step chart as a stacked bar chart in Excel which shows the Budget figure on the left and the A

  • Appearing for Abap Certification

    Haii All, i am appearing for the Certification Exam ""SAP Consultant Certification Development Consultant SAP NetWeaver 2004 – Application Development Focus ABAP"" next month. If anyone has already appeared for this exam, please help me regarding thi

  • Foolishly deleted Mail app now I want it back!!!!

    I deleted my Mail app thinking I would never need it, as I had been using Entourage, but now I actually want to use it - I am sick of the constant database corruptions I am getting with Entourage. So I went to my trusty Time Machine backup and restor