java - Which method is looked first by Compiler , Static or instance method when ClassName.staticMethod() is used? -
this question has answer here:
i want proper understanding why below compilation error? per understanding if use test.xyz() compiler static method not instance method why below compilation fail?
class test { public static void main(string arg[]) { test.xyz(10); // compilation fail } public void xyz(int i) { } public static void xyz(integer i) { } }
every 1 please suggest why compilation fail rather other suggestions , how use , i know basic thing autoboxing etc .
this question asked me which method looked first compiler , static or instance method when classname.method() used? in question of people go in wrong direction due mistake in question moved question new question.
you wrong in assumption: compiler first specific candidate methods signature (method name+parameters), without boxing. means selected method non static one.
then in second step compiler see call method static
1 syntax <class>.<method>()
.
it's why error.
Comments
Post a Comment