• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Which class or interface will be loaded into memory First ?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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]
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic