• Post Reply Bookmark Topic Watch Topic
  • New Topic

Which class or interface will be loaded into memory First ?  RSS feed

 
Aashish Vyas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

interface A
{
public void smile();
}

class Ok
{
public void smile() { System.out.println("Smile please..");}
}

class B extends Ok implements A {}

public class C
{
public static void main(String ... args)
{
B obj = new B();
obj.smile();
}
}
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aashish, and welcome to the Ranch!

We encourage people here to ShowSomeEffort,(⇐click) so what do you think the answer is, and why?

And why do you think it matters?

[EDIT: Hint: You'll find the answer somewhere around here http://docs.oracle.com/javase/specs/jvms/se5.0/html/Concepts.doc.html#19175 and/or here http://docs.oracle.com/javase/specs/jls/se5.0/html/execution.html]
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surely the exact details can vary from implementation to implementation?
 
Aashish Vyas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually I thought First Class C will be loaded into memory,Then interface A,Class Ok and Then Class B. I was not sure.

Thanks to all.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put some static blocks with print statements in those classes, and they will be printed in the order they are loaded. The loading order may differ depending which class loader you are using. I don’t think you can work that trick for the interface.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!