Win a copy of Modern frontends with htmx this week in the Spring forum!
  • 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

abstract class and interface

 
Ranch Hand
Posts: 481
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
what is the difference bewteen abstract class and interface ?

when we should we use interface and when should we use abstract class.

what is difference bewteen interface and class?

why should we have interface

I need why technical answer ?
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abstract class is used when you want to inherit something
interface is used when u want to implement something
they both sounds similar but are differnet.
regarding class and interface
in class u can define instance variables and methods
but in interface u can define methods but not instance variable but you can define variable with final,that should be implemented in all the classes.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

what is the difference bewteen abstract class and interface ?



Abstract class can contain some methods that are already implemented which subclasses can inherit their behaviour without modifying it.But interface will contain method definitions.Where if you want to create a concrete class which will be used to create objects then you must implement all the methods defined in the interface.

One good advantage of interface is it supports multiple inheritance.


what is difference bewteen interface and class?



Interface can not be instantiated. but class can be instantiated.I mean using interface you wont be able to create Object.

why should we have interface ?



Mainly to support multiple inheritance.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic