• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interface and abstract class  RSS feed

 
nagul samy
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.....

I have the knowledge of what is an interface and abstract class,But where exactly we have to use interface and abstract class??? Please Explain me with example....... ???
 
harshada patil
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you know the difference between Interface and Abstract class, you must be knowing that when we implement any Interface, we need to implement all methods in interface, but this is not the case with abstract classes, abstract class can exist without abstract function, and hence if we extend extend class you can override the methods of your interest only.

Example: if yo want to write event on MouseClick only, then there is no need to use MouseListener interface for it, you can simply use MouseAdapter and override required method. And if you want to write code for every event generated by mouse you can use MouseListener interface .
 
Rob Spoor
Sheriff
Posts: 21133
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nagul, please SearchFirst. This question has been asked so many times we even have an FAQ entry for it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!