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

Why bytecode is called bytecode?

793


How do you get the length of a string in java?

731


What are the important features of Java 10 release?

736


Give an example of use of pointers in java class.

747


What is a string token?

713


How do I print a “?

763


What is super in java?

757


Can static methods access instance variables in java?

772


Why can't you declare a class as protected?

788


Can the interface be final?

756


How do you make an arraylist empty in java?

670


What is java english?

676


If a method is declared as protected, where may the method be accessed in java programming?

696


Differentiate between class and structure.

800


Can I extend singleton class in java?

827