• 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

Difference between Abstract Class and interface in Java 8

 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends,

I tried to find answer outside wide world, but I failed, so I am asking this question here:

What is the difference between Abstract Class and interface in java 8, if it allows interface to have implementation of method also ?

Thanks for helping in understanding the new concept.
 
Author
Posts: 161
31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the (programmer) user point of view, the main difference is that everything in an interface is public, whether an abstract class may have private, package private, or protected members.
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java 9, it's likely that interfaces will be allowed to have private methods.

The two most important differences are that an abstract class can have instance fields but that a class can extend only one abstract class, and unlimited interfaces.

You should prefer the use of interfaces as much as possible. Use abstract classes only for default implementations that require private state.
 
R K Singh
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All enhancements to java, I am sure will turn out to be useful.

But being a old student, I still feel that by allowing public/private methods to interface we are somehow taking interface to a point where the only difference with class will be that interface will not have state (member variables). And who knows Java 11 may have that too ;-)

Anyways, java was proud to have solution for diamond shape, but now we have resolution operator in java also.

Thanks a lot for your inputs.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic