fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. class Product
  9. {
  10. }
  11.  
  12. class Mobile extends Product
  13. {
  14. }
  15.  
  16. class Market
  17. {
  18. public void buy(Product product)
  19. {
  20. System.out.println("Search a product in market");
  21. }
  22.  
  23. public void buy(Mobile mobile)
  24. {
  25. System.out.println("Search a mobile in market");
  26. }
  27. }
  28.  
  29. class Shop extends Market
  30. {
  31.  
  32. public void buy(Product product)
  33. {
  34. System.out.println("Search a product in shop");
  35. }
  36.  
  37. public void buy(Mobile mobile)
  38. {
  39. System.out.println("Search a mobile in shop.");
  40. }
  41. }
  42.  
  43. /* Name of the class has to be "Main" only if the class is public. */
  44. class Ideone
  45. {
  46. public static void main (String[] args) throws java.lang.Exception
  47. {
  48. System.out.println("Initial example");
  49. Market market = new Market();
  50. Market shop = new Shop();
  51.  
  52. market.buy(new Product());
  53. shop.buy(new Mobile());
  54. Product p1 = new Product();
  55. Product p2 = new Mobile();
  56.  
  57. System.out.println("New example");
  58. shop.buy(p1);
  59. shop.buy(p2);
  60. p1 = p2;
  61. shop.buy(p1);
  62.  
  63. }
  64. }
Success #stdin #stdout 0.06s 4386816KB
stdin
Standard input is empty
stdout
Initial example
Search a product in market
Search a mobile in shop.
New example
Search a product in shop
Search a product in shop
Search a product in shop