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. class Animal{ void speak(){ System.out.println("speak"); } }
  11. class Dog extends Animal{ void speak(){ System.out.println("woof!"); } }
  12. class Cat extends Animal{ void speak(){ System.out.println("meow!"); } }
  13. public class AnimalTest{
  14. public static void main( String[] args ){
  15. Animal[] animals = new Animal[3];
  16. animals[0] = new Animal();
  17. animals[1] = new Cat();
  18. animals[2] = new Dog();
  19. for( int i=0; i < animals.length; i++ )
  20. animals[i].speak();
  21. }
  22. }}
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:16: error: non-static variable this cannot be referenced from a static context
   animals[0] = new Animal(); 
                ^
Main.java:17: error: non-static variable this cannot be referenced from a static context
   animals[1] = new Cat(); 
                ^
Main.java:18: error: non-static variable this cannot be referenced from a static context
   animals[2] = new Dog(); 
                ^
Main.java:14: error: Illegal static declaration in inner class Ideone.AnimalTest
 public static void main( String[] args ){ 
                    ^
  modifier 'static' is only allowed in constant variable declarations
4 errors
stdout
Standard output is empty