Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. package kolos1;
  2.  
  3. public class Kolos1 {
  4.     public static void main(String[] args) {
  5.         B b = new B();
  6.         System.out.println(b.random());
  7.        
  8.         C c = new C(20);
  9.         System.out.println(c.random());
  10.        
  11.         F f = new F();
  12.        
  13.         System.out.println(f.sum(15, 20.5));
  14.         System.out.println(f.sum(15.7, 20));
  15.        
  16.         E e = new E()
  17.         {
  18.             public double sum(int x, double y)
  19.             {
  20.                 return x + y;
  21.             }
  22.         };
  23.         System.out.println(e.sum(100, 2.15));
  24.     }
  25.    
  26. }
  27.  
  28. abstract class A
  29. {
  30.     abstract int random();
  31. }
  32.  
  33. class B extends A
  34. {
  35.     int random()
  36.     {
  37.         return (int)(Math.random()*1000);
  38.     }
  39. }
  40.  
  41. class C extends A
  42. {
  43.     int max;
  44.     C(int max)
  45.     {
  46.         this.max = max;
  47.     }
  48.     int random()
  49.     {
  50.         return (int)(Math.random()*(max+1));
  51.     }
  52. }
  53.  
  54. interface D extends E
  55. {
  56.     double sum(double x, int y);
  57. }
  58.  
  59. interface E
  60. {
  61.     double sum(int x, double y);
  62. }
  63.  
  64. class F implements D
  65. {
  66.     public double sum(double x, int y)
  67.     {
  68.         return sum(y, x);
  69.     }
  70.    
  71.     public double sum(int x, double y)
  72.     {
  73.         return x + y;
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement