Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Dec 2013
    Location
    los angel
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Give some java ideas !

    Hi i am rafiq,

    What is the difference between an Interface and an Abstract class?

    i got some points in google but i want share this question with you all..

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    An interface is a contract which must be fulfilled before it can be accepted as the specified datatype.
    An abstract is a skeleton implementation for which some basic functionality can be programmed, but some needs to be customized. They are also used with minimal implementation where no functionality is abstract, but are used to enforce a contract such as an adapater class.
    Neither can be directly instantiated, and both can be constructed as anonymous types.
    In single inheritance languages like Java, interfaces are far more valuable than extends.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New Coder
    Join Date
    May 2014
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    An interface contains all the methods with empty implementation whereas an abstract class must have at least one method with empty implementation.

  • #4
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts
    In addition to what was already said, I'd like to point out that you can extend from only one class (whether abstract or not), but implement as many interfaces as you desire.

    When you derive from an abstract class, you must implement the abstract methods if you designed your derived class to be "concrete" (that is, not abstract). If you don't implement those abstract methods, you will still have an abstract class.

    On the other hand, when you implement an interface, you must implement all of the methods that the interface requires. Period.

    I hope that clears things up for you and welcome to CF!

  • #5
    New Coder
    Join Date
    Aug 2014
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Java Abstract classes are used to declare common characteristics of subclasses. An abstract class cannot be instantiated. It can only be used as a superclass for other classes that extend the abstract class. Abstract classes are declared with the abstract keyword. Abstract classes are used to provide a template or design for concrete subclasses down the inheritance tree.

    In Java, this multiple inheritance problem is solved with a powerful construct called interfaces. Interface can be used to define a generic template and then one or more abstract classes to define partial implementations of the interface. Interfaces just specify the method declaration (implicitly public and abstract) and can only contain fields (which are implicitly public static final). Interface definition begins with a keyword interface. An interface like that of an abstract class cannot be instantiated.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •