Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9109331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:01:13+00:00 2026-06-17T03:01:13+00:00

Consider the following code: import java.io.*; import java.util.*; class parent{ private static int static_count;

  • 0

Consider the following code:

    import java.io.*;
    import java.util.*;

    class parent{
      private static int static_count;
      final void static_display(){
       for(int i=0; i< 1000000; i++){
         Object obj = new Object();
       }
       System.out.println("Static method called"+static_count+"times");    
      }
      public void dynamic_display(){
        System.out.println("implemented in child");
      } 
    }

    class child extends parent{
      private static int dynamic_count;
      public void dynamic_display(){
        for(int i=0; i< 1000000; i++){
          Object obj = new Object();
        }
        System.out.println("dynamic method called"+dynamic_count+"times");    
      }
    }

    class sample{
      public static void main(String args[]){
      parent pnt= new parent();
      parent pnt2=new child();
      //static binding
      long startTime = System.nanoTime();
      pnt.static_display();
      long elapsedTime = System.nanoTime() - startTime;

      System.out.println("Total execution time for static binding in millis: "
            + elapsedTime/1000000);
      //dynamic binding
      long startTime2 = System.nanoTime();
      pnt2.dynamic_display();
      long elapsedTime2 = System.nanoTime() - startTime2;

      System.out.println("Total execution time for dynamic binding in millis: "
            + elapsedTime2/1000000);
     }
    }

When this code is executed i am getting the following answer,

    Static method called0times
    Total execution time for static binding in millis: 11
    dynamic method called0times
    Total execution time for dynamic binding in millis: 9

consider only the execution time in the result.i tried to find the time taken for statically and dynamically binnded method to execute.but according to my answer,dynamic binding is faster than static binding.how is this possible.am i wrong anywhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:01:14+00:00Added an answer on June 17, 2026 at 3:01 am

    It looks as though all your tests do the runs in the same order, static then dynamic. The JVM may have decided to optimize your code, because of the amount of time it is running, part way through the static test. The static test would get all the cost of optimization, and some benefit. The dynamic code would get the benefit.

    This is just one example of the sorts of issues you can hit with this sort of micro-benchmarking of Java code.

    If you want meaningful results, take the real program you are working on and test in context. If the difference is too small to measure in actual use, it is too small to outweigh code clarity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following simple code import java.util.*; public class MainTest<T extends Object1<?,?>> { List<T>
Consider the following code: template <class x1, class x2 = int*> struct CoreTemplate {
Consider the following code in C: void main() { int a=0; for(printf(\nA); a; printf(\nB));
consider the following python code: import gtk class MainWindow(): def __init__(self): self.window = gtk.Window()
Consider the following simple example of code: public class TestStaticImport { static enum Branches
Please consider the following code fragment: import java.awt.FlowLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.lang.reflect.InvocationTargetException;
Consider the following code: A.java: import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.RUNTIME) @interface A{} C.java: import
Consider the following (broken) code: import functools class Foo(object): def __init__(self): def f(a,self,b): print
Consider the following code: $(document).ready(function() { $(body).append(<div class='outer'><span class='inner'>Click me</span></div>); $(html).click(function(event) { var targetClass
Consider the following code. public interface IFoo { } public class Bar { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.