Search code examples
javamemoryinterface

Java interfaces and memory accolcation


Suppose you have a class Delta that implements interface Alpha. Alpha has methods a, b, and c, and Delta defines an additional method d. If the line "Alpha object = new Delta()" is written, will the compiler allocate memory for the method d even though the reference will not be able to access it?


Solution

  • Yes, the memory will be allocated for the method 'd'. It won't be 'visible' if you try to access it via Alpha reference without casting. But because you are creating an object of type Delta the method 'd' is there.