Results 1 to 11 of 11

Thread: give me clear concept about interface and abstract.

  1. #1
    Junior Member
    Join Date
    Jul 2008
    Answers
    3

    Question give me clear concept about interface and abstract.

    also kindly specify difference b/w them with one brief example .( if you dont mind)


  2. #2
    Junior Member
    Join Date
    Feb 2008
    Answers
    11

    Smile Re: give me clear concept about interface and abstract.

    *In interface the methods are only declare not define,but abstract class the methods are define and declare.
    *we can not create object for abstract class,but can create object for interface class.
    *we should use(define) all the interface class' methods in derived class.if we did not use all methods,the interface class will be abstract class.


  3. #3
    Junior Member
    Join Date
    Jan 2008
    Answers
    5

    Re: give me clear concept about interface and abstract.

    the simple and basic differences between abstract and interface are

    1) Interface is a pure abstract class where as abstract class not .
    2) Abstract class can have one or none abstract methods where as interface have all the methods by default public static absatrct.
    3)Interface has attributes by default public static final.


  4. #4
    Junior Member
    Join Date
    Jul 2008
    Answers
    1

    Re: give me clear concept about interface and abstract.

    Abstract Class
    ● An abstract class is a class that contains one or
    more abstract methods
    ● An abstract class cannot instantiated
    // You will get a compile error on the following code
    MyAbstractClass a1 = new MyAbstractClass();
    ● Another class (Concrete class) has to provide
    implementation of abstract methods
    – Concrete class has to implement all abstract methods of
    the abstract class in order to be used for instantiation
    – Concrete class uses extends keyword

    Sample Abstract Class
    public abstract class LivingThing {
    public void breath(){
    System.out.println("Living Thing breathing...");
    }
    public void eat(){
    System.out.println("Living Thing eating...");
    }
    /**
    * Abstract method walk()
    * We want this method to be imp

    Extending an Abstract Class
    ● When a concrete class extends the LivingThing
    abstract class, it must implement the abstract
    method walk(), or else, that subclass will also
    become an abstract class, and therefore cannot be
    instantiated.
    ● For example,
    public class Human extends LivingThing {
    public void walk(){
    System.out.println("Human walks...");
    }
    }
    What is an Interface?
    ● It defines a standard and public way of specifying
    the behavior of classes
    – Defines a contract
    ● All methods of an interface are abstract methods
    – Defines the signatures of a set of methods, without the
    body (implementation of the methods)
    ● A concrete class must implement the interface (all
    the abstract methods of the Interface)
    ● It allows classes, regardless of their locations in the
    class hierarchy, to implement common behaviors

    11
    Example: Interface
    // Note that Interface contains just set of method
    // signatures without any implementations.
    // No need to say abstract modifier for each method
    // since it assumed.
    public interface Relation {
    public boolean isGreater( Object a, Object b);
    public boolean isLess( Object a, Object b);
    public boolean isEqual( Object a, Object b);
    }


  5. #5
    Junior Member
    Join Date
    Jul 2008
    Answers
    1

    Re: give me clear concept about interface and abstract.

    what is recovery testing plz reply me?


  6. #6
    Junior Member
    Join Date
    Jul 2008
    Answers
    3

    Post Re: give me clear concept about interface and abstract.

    [QUOTE=ananth3335;32965]*In interface the methods are only declare not define,but abstract class the methods are define and declare.
    *we can not create object for abstract class,but can create object for interface class.
    *we should use(define) all the interface class' methods in derived class.if we did not use all methods,the interface class will be abstract class.
    /QUOTE]

    I thank you sincerely for giving a quick response for my doubts and for clarifying them with such a good example. thanyou once again.


  7. #7
    Junior Member
    Join Date
    Jul 2008
    Answers
    3

    Re: give me clear concept about interface and abstract.

    Quote Originally Posted by ajmeer_007 View Post
    Abstract Class
    ● An abstract class is a class that contains one or
    more abstract methods
    ● An abstract class cannot instantiated
    // You will get a compile error on the following code
    MyAbstractClass a1 = new MyAbstractClass();
    ● Another class (Concrete class) has to provide
    implementation of abstract methods
    – Concrete class has to implement all abstract methods of
    the abstract class in order to be used for instantiation
    – Concrete class uses extends keyword

    Sample Abstract Class
    public abstract class LivingThing {
    public void breath(){
    System.out.println("Living Thing breathing...");
    }
    public void eat(){
    System.out.println("Living Thing eating...");
    }
    /**
    * Abstract method walk()
    * We want this method to be imp

    Extending an Abstract Class
    ● When a concrete class extends the LivingThing
    abstract class, it must implement the abstract
    method walk(), or else, that subclass will also
    become an abstract class, and therefore cannot be
    instantiated.
    ● For example,
    public class Human extends LivingThing {
    public void walk(){
    System.out.println("Human walks...");
    }
    }
    What is an Interface?
    ● It defines a standard and public way of specifying
    the behavior of classes
    – Defines a contract
    ● All methods of an interface are abstract methods
    – Defines the signatures of a set of methods, without the
    body (implementation of the methods)
    ● A concrete class must implement the interface (all
    the abstract methods of the Interface)
    ● It allows classes, regardless of their locations in the
    class hierarchy, to implement common behaviors

    11
    Example: Interface
    // Note that Interface contains just set of method
    // signatures without any implementations.
    // No need to say abstract modifier for each method
    // since it assumed.
    public interface Relation {
    public boolean isGreater( Object a, Object b);
    public boolean isLess( Object a, Object b);
    public boolean isEqual( Object a, Object b);
    }
    Thank you very much for spending your high time for me. Also for your excellent example which made my doubts clear. Thankyou once again ...


  8. #8
    Junior Member
    Join Date
    Aug 2008
    Answers
    6

    Re: give me clear concept about interface and abstract.

    An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.


  9. #9
    Expert Member
    Join Date
    Jan 2007
    Answers
    141

    Re: give me clear concept about interface and abstract.

    Hi Friend,

    Go through this link its really useful

    interface vs abstract class : Java Glossary

    Cheers,
    Sridevichitthu


  10. #10
    Junior Member
    Join Date
    Oct 2007
    Answers
    1

    Re: give me clear concept about interface and abstract.

    In abstract class, the method may be declared with body / without method body. But in Interface the method body cannot be defined.


  11. #11
    Junior Member
    Join Date
    Aug 2008
    Answers
    2

    Re: give me clear concept about interface and abstract.

    Abstract class has abstract methods as well as non abstract methods where as in interface has only abstract methods but not marked with abstract. In abstract class there is different flavor of method like public, private etc... But in interface only public methods and public final instance variable with only definition. Where to use abstract class and where interface ============================================ if sub class required extends another class then use interface because java dose not support multiple inheritance.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact