java - Abstract Class with only abstract methods and Interface - Which should I use? -


this question has answer here:

please note. question not abstract class vs interface kind of question.

yes. know. it's not necessary class extends abstract class override of unimplemented methods. if child class not giving definition of parent's unimplemented methods, child class considered abstract.

but class implements interface should implement of methods ( multiple inheritance possible interfaces).

is difference between abstract class abstract methods , interface?

yes, understand. abstract class can have states , method implementations. i'm making question clear. not interface vs abstract class kind of question.

here, in question, abstract class not having data members or method implementations. abstract methods only. eg:

abstract class shape{     abstract void draw(); } 

i want know whether there other differences. should use in such scenario?

please help.

i believe question not 1 vs other how know 1 choose in instance.

a way think interfaces tend actions available user interface class. example, if class implemented interface playable know have play method, whether starting audio player, starting video, or starting game depend on class itself, know playable class , can play.

whereas shape not action, type, shape comes along attributes define it, need know color, size, etc. in order know shape. why use abstract class define of properties have in common.

because draw() functionality can apply shapes, images, or scenes implement drawable interface.

example:

 public class square extends shape implements drawable{        public void draw(){           //draw code here       }  } 

this way can define common properties inside of shape , provide functionality draw through drawable interface.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -