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. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public class Base {
  11. private int x;
  12. public void Base() { x = 0; }
  13. public void inc() { x++; }
  14. public int get() { return x; }
  15. };
  16.  
  17. class FilhaUm extends Base {
  18. private int x;
  19. public void FilhaUm() { x = 1; }
  20. public void inc() { x++; }
  21. };
  22.  
  23. class FilhaDois extends Base {
  24. private int x;
  25. public void FilhaDois() { x = 2; }
  26. public int get() { return x; }
  27. };
  28.  
  29.  
  30. class FilhaTres extends Base {
  31. private int x;
  32. public void FilhaTres() { x = 3; }
  33. public void inc() { x++; }
  34. public int get() { return x; }
  35. };
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. public static void main (String[] args) throws java.lang.Exception
  44. {
  45.  
  46. Base p1 = new FilhaUm();
  47. Base p2 = new FilhaDois();
  48. Base p3 = new FilhaTres();
  49. p1.inc();
  50. p2.inc();
  51. p3.inc();
  52. System.out.println(p1.get);
  53. System.out.println(p2.get);
  54. System.out.println(p3.get);
  55. }
  56. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:46: error: non-static variable this cannot be referenced from a static context
  Base p1 = new FilhaUm();
            ^
Main.java:47: error: non-static variable this cannot be referenced from a static context
  Base p2 = new FilhaDois();
            ^
Main.java:48: error: non-static variable this cannot be referenced from a static context
  Base p3 = new FilhaTres();    
            ^
Main.java:52: error: cannot find symbol
  System.out.println(p1.get);
                       ^
  symbol:   variable get
  location: variable p1 of type Ideone.Base
Main.java:53: error: cannot find symbol
  System.out.println(p2.get);
                       ^
  symbol:   variable get
  location: variable p2 of type Ideone.Base
Main.java:54: error: cannot find symbol
  System.out.println(p3.get);
                       ^
  symbol:   variable get
  location: variable p3 of type Ideone.Base
6 errors
stdout
Standard output is empty