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 to restrict a member of a class from inheriting by its sub classes?

795


Differences between traditional programming language and object oriented programming language?

568


what is the significance of listiterator in java?

616


What do you understand by access specifiers in Java?

582


What are the ways to instantiate the class class?

595






What is the difference between equals() and == in java?

521


Does unicode support all languages?

516


How many unicode characters are there?

550


How will you initialize an Applet?

616


Explain about sets?

565


When do we use synchronized methods in java?

582


What is the flag in java?

608


What is the final access modifier in java?

610


what is instanceof operator used in java?

589


What is a native method in java programming?

523