• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Interface

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are all the similarities of interfaces and abstract class?
What are all the differences between interfaces and abstract class?
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Kesavan,
Similartities are :
1. Both are the means of declaring abstract methods.
2.Both forces its subclasses to implement the methods declared abstract in Interface/Abstract class.
3. In case the implementing/extending class doesn't provide implementation of abstract methods defined in Interface/Abstract class, the implementing class must be declared abstract.

Differences are :
1. A class can implement one or more interfaces at a time, on the other side, a class can extend only one class abstract or otherwise at a time.
2. Interfaces can't have concrete methods, while abstract classes may have concrete methods.
3. Variables defined in a Interface are final and static, while in an abstract class variables may be of any type.
4. In case of interface,methods implemented in the implementing class must declared as public. While in case of abstract classes, methods implemented in the extending class must be of the same signature as in the abstract class.
Hope, now get cleared !
Regards,
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
some more differences are
1)abstract classes may have a constructor while a interface cannot have a constructor
2)methods in an abstract class may be private. while in interfaces they are public by default
abstract class y
{
y(){// constructor
System.out.println("in y");
}
}
class demo extends y
{
public static void main(String[] args)
{
demo xxx =new demo();
System.out.println("Hello World!");
}
}

prints out "in y"
"hello world"
Regds
Rahul.

[This message has been edited by rahul_mkar (edited June 27, 2000).]
 
KESAVAN RAMANUJAM
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi raghul
thanks a lot
regards
kesavan
 
KESAVAN RAMANUJAM
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi sam
thanks a lot
regards
kesavan
 
I am going to test your electrical conductivity with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic