Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Abstract Classes?

  1. #1
    Member
    Join Date
    Aug 2012
    Posts
    67
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Abstract Classes?

    Could anyone explain to me the use of an abstract class and why I would prefer them over an interface?

    As far as I understand, both contain empty method declarations, except that you can implement the interface while you can't implement an abstract class, so what's the use?


  2. #2
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    My Mood
    Happy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Abstract Classes?

    1Interface is the concept of encapsulation
    – The implementation can change without affecting the caller of the interface
    – The caller does not need the implementation at the compile time
    ● It needs only the interface at the compile time
    ● During runtime, actual object instance is associated with the interface type
    2. Example:
    – Class Line and class MyInteger
    ● They are not related through inheritance
    ● You want both to implement comparison methods
    – checkIsGreater(Object x, Object y)
    – checkIsLess(Object x, Object y)
    – checkIsEqual(Object x, Object y)
    – Define Comparison interface which has the three abstract methods above
    3. A class can implement multiple interfaces while it can extend only one class

Similar Threads

  1. what is the use of interfaces and abstract classes?
    By sagar474 in forum Java Theory & Questions
    Replies: 5
    Last Post: September 18th, 2011, 02:34 PM
  2. Interfaces Vs Abstract classes
    By tcstcs in forum Java Theory & Questions
    Replies: 1
    Last Post: April 20th, 2011, 07:49 AM
  3. Issue with abstract classes
    By zaphod2003 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 7th, 2011, 02:25 AM
  4. [SOLVED] Abstract Classes Help
    By SweetyStacey in forum Object Oriented Programming
    Replies: 10
    Last Post: May 6th, 2010, 06:15 AM
  5. Java program with abstract class along with two subclasses
    By crazydeo in forum Collections and Generics
    Replies: 2
    Last Post: June 10th, 2008, 11:45 AM