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
Can we print null in java?
Can you inherit from an abstract class java?
there are N number of matchboxes numbered 1...N.each matchbox contain various number of stick.Two player can alternatevely pick some amount of stick from the higest stick containing box . The player is condidered win if there is no stick after his move.Find the final move so that the move player win. Note:In case the number of stick is equal ,pick the stick from the higest numbered box.
What is a variable and constant?
What is nan inf?
What types of index data structures can you have in java?
Why is string buffer better than string ?
what do you understand by synchronization? : Java thread
What is fail fast in java?
What is diamond operator in java?
What is the purpose of file class?
What comes to mind when someone mentions a shallow copy in java?
What is map and hashmap in java?
How is java created?
What happens if I remove static from main method?