I wrote this program in net-beans. It says I can't pass 'null' value to a method (overloaded) when there is a overloaded method which accept a String and a overloaded method which accept a Object.
reference to enroll is ambiguous both method enroll(java.lang.String) in object.Str and method enroll(object.Object) in object.Str match
Then I ran the same program with cmd. And It compiled well. Null value has passed to the method which accept a String. output -
String
Why that happens like that?
The code
class Str {
void enroll(String du){
System.out.println("String");
}
void enroll(Object o){
System.out.println("Object");
}}
class worker{
public static void main(String[] args) {
Str s = new Str();
s.enroll(null);
}}