What is the difference between extends and implements in java with respect to performance and memory,etc. For example take the following scenarios,
1)
public interface PrintResult
{
public final int NO_ERROR=0;
public final int SUCCESS=1;
public final int FAILED=-1;
}
public class PrintProcess implements PrintResult
{
//Perform some operation
}
2)
public class PrintResult
{
public final int NO_ERROR=0;
public final int SUCCESS=1;
public final int FAILED=-1;
}
public class PrintProcess extends PrintResult
{
//Perform some operation
}
For above scenarios (1,2) what is difference between using extends (deriving child class), implements (implementing interface). with respect to performance,memory,etc. ?
During a memorable Q&A session, someone asked James Gosling (Java's inventor): If you could do Java over again, what would you change? . I'd leave out classes, he replied
Java does not allow you to extend multiple classes. This avoids some problems related to multiple inheritance. However you can choose to implement multiple interfaces. This is a huge plus.
Some people also believe extends
decreases the flexibility of their code.
However, I doubt there is any huge difference in performance, efficiency etc. In fact, they might even produce the same byte-code ( though I'm not sure ). And you are comparing two different things that have different functions, its like asking if Apples are more efficient than Oranges.