• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Difference between Abstract Class and interface in Java 8

 
Ranch Hand
Posts: 5397
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: 12990
281
  • 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: 5397
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.
 
I was born with webbed fish toes. This tiny ad is my only friend:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic