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

What is r * in math?

554


Can you create an object of an abstract class?

555


Are arrays static in java?

588


what is recursion in java

601


What is an enumeration?

572






What are the differences between stringbuffer and stringbuilder?

541


What are predicates in java 8?

533


What is difference between public static and void?

486


How destructors are defined in java?

632


What is the benefit of inner / nested classes ?

527


what is function overloading in java?

698


Does java have a compiler?

560


How many bits are in a sentence?

585


What is comparator in java?

559


How do you detect memory leaks?

584