Advertisement
apds26

SSU_CPE6_Exercise1

Aug 18th, 2022
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | Source Code | 0 0
  1. // Java program to Demonstrate Polymorphism
  2.  
  3. // This class will contain
  4. // 3 methods with same name,
  5. // yet the program will
  6. // compile & run successfully
  7. public class Sum {
  8.  
  9.     // Overloaded sum().
  10.     // This sum takes two int parameters
  11.     public int sum(int x, int y)
  12.     {
  13.         return (x + y);
  14.     }
  15.  
  16.     // Overloaded sum().
  17.     // This sum takes three int parameters
  18.     public int sum(int x, int y, int z)
  19.     {
  20.         return (x + y + z);
  21.     }
  22.  
  23.     // Overloaded sum().
  24.     // This sum takes two double parameters
  25.     public double sum(double x, double y)
  26.     {
  27.         return (x + y);
  28.     }
  29.  
  30.     // Driver code
  31.     public static void main(String args[])
  32.     {
  33.         Sum s = new Sum();
  34.         System.out.println(s.sum(10, 20));
  35.         System.out.println(s.sum(10, 20, 30));
  36.         System.out.println(s.sum(10.5, 20.5));
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement