Overloading concept: which function will be called and why?

Class Student { 

 public void setName(String name){
   //Some implementation
 }

 public void setName(Object name){
  // some implementation
 }
}

      

I have a Student class with overloading methods, I just want to know which method will be called and why?

Student s = new Student()
 s.setName("abc");

      

CHANGE Language: JAVA

+3


source to share


1 answer


It will call the function setName(String name)

as you are passing in String

, not an object String

.



0


source







All Articles