what do you mean by class and its instance ? (java) -
while checking questions found question. asks relationship between flower , rose. choices inheritance, class , instance , interface & implementation.
now problem answer should know inheritance, answer class , instance. know class , instance mean? know instance means object of class.
thank time.
a class template
objects
created. in example mentioned, flower class rose
, dandelion
, lily
, etc instances. eg,
public class flower { private string type; .. public flower(string type) { this.type = type; } .. }
and create instances of
flower rose = new flower("rose"); flower lily = new flower("lily");
this viable explanation.
i can see logical thought process well. have been
public class flower { .. }
and subclass like
public class rose extends flower { .. }
and
public class lily extends flower { .. }
but, subtleties depends on implementation. depends on how see problem (or rather how questioner saw problem). an interface , implementation
. again, depends on implementation.
update 1 there multiple levels of inheritance
can make out problem statement. depends on level of detail require in application. if want see flower entity, use flower
class , different instances of flower objects.
another scenario when see level of detail in flowers. want talk different types of roses, or different types of lilies, on color, size, locations, seasons, etc. in case, flower
class no sufficient. rose
might have details (properties
) relevant roses, , lily
might have relevant lilies. @ point, flower
no longer relevant give no important information whatsoever. now, use flower
abstract class
or interface
, denote higher level properies
or ensure implementations
sure found. , create individual classes each of inherited flowers rose
, lily
.
hope clears doubt
Comments
Post a Comment