Thursday 26 July 2018

Give a real time scenario example for Polymorphism/method overloading ? Interview qus selenium webdriver/java/method overloading

public class testuu{
public static void main(String as[]) throws Throwable {
System.out.println("sum is: " + sum(14,0) + " sum of three params is: " + sum(1,2,3));
}
public static int sum(int a, int b) throws Exception {
int sum = a+b;
return sum;
}
private static int sum(int a, int b, int c) {
int sum = a+b+c;
return sum;
}
}

Output:
sum is: 14
sum of three params is: 6

//In above example we have two method with same name as "sum" but we have pass different parameters which is an perfect example for method overloading or polymorphism.

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

API Status Codes with examples for QA-Testers

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 🏮In API testing, it...