class A { public void hello() { System.out.println("hello in A"); } } class B extends A { public void hello() { System.out.println("hello in B"); } } class C { public static void main(String... args) { A a = new B(); a.hello(); } }
hello in B
public class StaticBindingTest { public static void main(String args[]) { Collection c = new HashSet(); StaticBindingTest et = new StaticBindingTest(); et.sort(c); } //overloaded method takes Collection argument public Collection sort(Collection c){ System.out.println("Inside Collection sort method"); return c; } //another overloaded method which takes HashSet argument which is sub class public Collection sort(HashSet hs){ System.out.println("Inside HashSet sort method"); return hs; } } Output: Inside Collection sort method hows its possible i think in second case output will be "Inside HashSet sort method" please correct me if i'm wrong
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)