fork 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. abstract class ParentClass {
  9. public abstract void methodA();
  10. }
  11.  
  12. class ChildClass1 extends ParentClass {
  13. public void methodA() {
  14. System.out.println("Implementation from ChildClass1");
  15. }
  16. }
  17.  
  18. class ChildClass2 extends ChildClass1 {
  19. public void methodA() {
  20. System.out.println("Implementation from ChildClass2");
  21. }
  22. }
  23.  
  24. class ChildClass3 extends ChildClass2 {
  25. // ChildClass3 inherits the implementation of methodA from ChildClass2
  26. // It does not need to provide its own implementation
  27. }
  28.  
  29.  
  30. /* Name of the class has to be "Main" only if the class is public. */
  31. class Ideone
  32. {
  33. public static void main (String[] args) throws java.lang.Exception
  34. {
  35. // your code goes here
  36. ChildClass3 object = new ChildClass3();
  37. object.methodA(); // Output: "Implementation from ChildClass2"
  38. }
  39. }
Success #stdin #stdout 0.08s 40880KB
stdin
Standard input is empty
stdout
Implementation from ChildClass2