fork download
  1. class Bay extends Lake{
  2.  
  3. public void method1(){
  4.  
  5. System.out.print("Bay 1 ");
  6.  
  7. super.method2();
  8.  
  9. }
  10.  
  11. public void method2(){
  12.  
  13. System.out.print("Bay 2");
  14.  
  15. }
  16.  
  17. }
  18.  
  19. class Pond{
  20.  
  21. public void method1(){
  22.  
  23. System.out.print("Pond 1");
  24.  
  25. }
  26.  
  27. public void method2(){
  28.  
  29. System.out.print("Pond 2");
  30.  
  31. }
  32.  
  33. public void method3(){
  34.  
  35. System.out.print("Pond 3");
  36.  
  37. }
  38.  
  39. }
  40.  
  41. class Ocean extends Bay{
  42.  
  43. public void method2(){
  44.  
  45. System.out.print("Ocean 2");
  46.  
  47. }
  48.  
  49. }
  50.  
  51. class Lake extends Pond {
  52.  
  53. public void method3(){
  54.  
  55. System.out.print("Lake 3");
  56.  
  57. method2();
  58.  
  59. }
  60.  
  61. }
  62.  
  63. class Exaple{
  64. public static void main(String args[]){
  65. Pond[] ponds = {new Ocean(), new Pond(), new Lake(), new Bay()};
  66.  
  67. for(Pond p : ponds){
  68.  
  69. p.method1();
  70.  
  71. System.out.println();
  72.  
  73. p.method2();
  74.  
  75. System.out.println();
  76.  
  77. p.method3();
  78.  
  79. System.out.println("\n");
  80.  
  81. }
  82. }
  83. }
Success #stdin #stdout 0.09s 48016KB
stdin
Standard input is empty
stdout
Bay 1 Pond 2
Ocean 2
Lake 3Ocean 2

Pond 1
Pond 2
Pond 3

Pond 1
Pond 2
Lake 3Pond 2

Bay 1 Pond 2
Bay 2
Lake 3Bay 2