Solved

Java JVM Method Invocation

Posted on 2013-02-01
6
2,543 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
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!

 
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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…
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

752 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