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
Which are the two subclasses under exception class?
What is set in java?
Is java util list serializable?
How can we find the sum of two linked lists using stack in java?
Can we define a package statement after the import statement in java?
What is string array?
How to connect to a remote database using Applet?
Can we assign null to double in java?
Explain reverse a linked list recursive java solution?
What is the arraylist in java?
What is difference between calling start() and run() method of thread?
What is temp in java?
What is the difference between call by reference and call by pointer?
How many arguments can a method have java?
Why string is not thread safe?