Solved

Java JVM Method Invocation

Posted on 2013-02-01
6
2,552 Views
Last Modified: 2013-02-01
Method Invocation
When the following Java code is run by the JVM, what is the order of method invocation? Assume the class Foo has not been loaded yet.
new Foo().getName();

a) <init>, <clinit>, getName
b) getName, <clinit>, <init>
c) <clinit>, <init>, getName
d) None of the above
0
Comment
Question by:javaagile
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 38843282
We're not allowed/here to do your homework. Sorry.
0
 

Author Comment

by:javaagile
ID: 38843351
this is not homework. I need to understand what happens in jvm internally when a method is invoked.
0
 
LVL 37

Accepted Solution

by:
zzynx earned 500 total points
ID: 38843387
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 37

Expert Comment

by:zzynx
ID: 38843423
Thanx 4 axxepting
0
 
LVL 14

Expert Comment

by:CPColin
ID: 38844398
Hi javaagile,

This is one of those cases where "try it and see" would have been the best advice anybody could give you. You could have done something like this and found the answer in much less time:

public class Foo
{
   static
   {
      System.out.println("In <clinit>");
   }

   public Foo()
   {
      System.out.println("In <init>");
   }

   public void getName()
   {
      System.out.println("In getName()");
   }
}

Open in new window


If you're really interested in learning and using Java, you'll do thousands of little investigations just like this. Best get used to it, if you ask me.
0
 

Author Comment

by:javaagile
ID: 38845449
Thanks CPColin, I knew this execution order but was not familiar with terms like <clinit> and <init>
1

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question