• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2601
  • Last Modified:

Java JVM Method Invocation

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
javaagile
Asked:
javaagile
  • 3
  • 2
1 Solution
 
zzynxSoftware engineerCommented:
We're not allowed/here to do your homework. Sorry.
0
 
javaagileAuthor Commented:
this is not homework. I need to understand what happens in jvm internally when a method is invoked.
0
 
zzynxSoftware engineerCommented:
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
zzynxSoftware engineerCommented:
Thanx 4 axxepting
0
 
CPColinSenior Java ArchitectCommented:
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
 
javaagileAuthor Commented:
Thanks CPColin, I knew this execution order but was not familiar with terms like <clinit> and <init>
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now