[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2589
  • 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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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