When we r go to abstract class and when we go to Interface?
i have confusion this question while in interview plz clarify

Answer Posted / nani

If we want share some common features with all we can go for
abstract otherwise we can prefer interface .
i will give good example to understand easily.
Ex: wholesaler has books and stationary(pens & papers)

supplier1 ask for X class books and Pens
Supplier2 ask for X class books and papers.

here both suppliers asking same standard books and different
stationary items.suppose we can take it as by methods, here
here books methods are common to shared by both suppliers.so
book method is non abstract class. so here we can prefer
abstract.



supplier1 ask for X class books and Pens
Supplier2 ask for V class books and papers.

here both suppliers asking different standard books and
different stationary items.

Is This Answer Correct ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How objects are stored in java?

548


What is %02d?

575


Can a lock be acquired on a class in java programming?

534


Can inner class final?

633


Why should I use abstract class?

568






What is the difference between the file and randomaccessfile classes?

532


Is there any case when finally will not be executed?

521


What are the wrapped, classes?

599


Java.util.regex consists of which classes?

544


What is an object's lock and which object's have locks in java programming?

567


How thread scheduler schedule the task?

584


Which package is used for pattern matching with regular expressions?

645


Can you declare an interface method static?

583


Difference between abstract and concrete class ?

581


What is mnemonic code?

539