title: Java Overloaded AND Overridden Methods
body: <p>In the following program, I have one single method in class A overloaded 3 times and then in subclass B, all 3 overloaded methods are overridden.</p>
  <p>obj3 is an object with reference type A(superclass) and object type B(subclass) and it calls the method from B on execution, which is expected behavior.</p>
  <p>Since overloading and overriding both exist in this code, does that mean that it performed static binding at compile time (to the matching method in class A) and then dynamic binding at run time (to method in class B). Can they both occur together?</p>
  <p>My assumption is that this is a classic case of dynamic binding as I believed &quot;binding&quot; is meant to be a permanent action, but a peer suggests that it is both together(static first, then dynamic).</p>
  <pre><code>class A{
      
      public void method(Integer n){
          System.out.println(&quot;Integer: &quot;+n);
      }
      
      public void method(String s){
          System.out.println(&quot;String: &quot;+s);
      }
      
      public void method(String s, Integer n){
          System.out.println(&quot;String: &quot;+s+&quot; Integer: &quot;+n);
      }
  }
  
  class B extends A{
      
      public void method(Integer n){
          System.out.println(&quot;Integer(from B): &quot;+n);
      }
      
      public void method(String s){
          System.out.println(&quot;String(from B): &quot;+s);
      }
      
      public void method(String s, Integer n){
          System.out.println(&quot;String(from B): &quot;+s+&quot; Integer(from B): &quot;+n);
      }
  }
  
  public class Test{
      public static void main(String[] args){
          A obj1 = new A();
          B obj2 = new B();
          A obj3 = new B();
          
          System.out.println(&quot;Integer form of method&quot;);
          // Integer form of method
  
          System.out.println(&quot;Ref A Obj A&quot;);
          // Ref A Obj A
          obj1.method(1);
          // Integer: 1
          
          System.out.println(&quot;Ref B Obj B&quot;);
          // Ref B Obj B
          obj2.method(2);
          // Integer(from B): 2
          
          System.out.println(&quot;Ref A Obj B&quot;);
          // Ref A Obj B
          obj3.method(3);
          // Integer(from B): 3
          
      }
  }
  </code></pre>