Solved

Java JVM Method Invocation

Posted on 2013-02-01
6
2,530 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
  • 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

777 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