Browse Today's favorites or All time favorites.
Please Sign In or Register to share and submit your questions.
Java Queries
Complete java interview questions library
Home » Interview Questions » Core Java Interview Questions » What are some alternatives to inheritance?
What are some alternatives to inheritance?
Delegation is an alternative to inheritance. Delegation means that you include an instance of another class as an instance variable, and forward messages to the instance. It is often safer than inheritance because it forces you to think about each message you forward, because the instance is of a known class, rather than a new class, and because it doesn’t force you to accept all the methods of the super class: you can provide only the methods that really make sense. On the other hand, it makes you write more code, and it is harder to re-use (because it is not a subclass).
Follow up with a Thank-You Note
Make sure you let the interviewer know how pleased you were to have the chance to interview with him or her. Immediately after the interview, send the interviewer a thank-you note, thanking him or her for taking time to interview you.
Write a comment