fork download
  1. // Example program
  2. #include <iostream>
  3. class ZooAnimal
  4. {
  5. public:
  6. virtual void spec() const
  7. {
  8. cout << "Address:\n" << "Sofia, Bulgaria\n";
  9. }
  10. void print () const
  11. {
  12. cout << "ZooAnimal\n";
  13. spec();
  14. }
  15. };
  16. class Cat : Public ZooAnimal
  17. {
  18. public
  19. virtual void spec() const
  20. {
  21. cout <<"Cat\n";
  22. }
  23. };
  24. class Mouse : Public ZooAnimal
  25. {
  26. public
  27. virtual void spec() const
  28. {
  29. cout <<"Mouse\n";
  30. }
  31. };
  32. class Bear : Public ZooAnimal
  33. {
  34. public
  35. virtual void spec() const
  36. {
  37. cout <<"Bear\n";
  38. }
  39. };
  40. void main()
  41. {
  42. ZooAnimal zoo; zoo.print()
  43. Cat c; c.print();
  44. Mouse m; m.print();
  45. Bear b; b.print();
  46. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:2: error: illegal character: '#'
#include <iostream>
^
Main.java:2: error: class, interface, or enum expected
#include <iostream>
         ^
Main.java:5: error: illegal start of type
    public:
          ^
Main.java:5: error: ';' expected
    public:
           ^
Main.java:6: error: ';' expected
    virtual void spec() const
                       ^
Main.java:8: error: not a statement
        cout << "Address:\n" << "Sofia, Bulgaria\n";
                             ^
Main.java:10: error: ';' expected
    void print () const
                 ^
Main.java:12: error: not a statement
        cout << "ZooAnimal\n";
             ^
Main.java:16: error: '{' expected
class Cat : Public ZooAnimal
         ^
Main.java:19: error: <identifier> expected
    virtual void spec() const
           ^
Main.java:19: error: invalid method declaration; return type required
    virtual void spec() const
                 ^
Main.java:19: error: ';' expected
    virtual void spec() const
                       ^
Main.java:21: error: not a statement
        cout <<"Cat\n";
             ^
Main.java:24: error: '{' expected
class Mouse : Public ZooAnimal
           ^
Main.java:27: error: <identifier> expected
    virtual void spec() const
           ^
Main.java:27: error: invalid method declaration; return type required
    virtual void spec() const
                 ^
Main.java:27: error: ';' expected
    virtual void spec() const
                       ^
Main.java:29: error: not a statement
        cout <<"Mouse\n";
             ^
Main.java:32: error: '{' expected
class Bear : Public ZooAnimal
          ^
Main.java:35: error: <identifier> expected
    virtual void spec() const
           ^
Main.java:35: error: invalid method declaration; return type required
    virtual void spec() const
                 ^
Main.java:35: error: ';' expected
    virtual void spec() const
                       ^
Main.java:37: error: not a statement
        cout <<"Bear\n";
             ^
Main.java:40: error: class, interface, or enum expected
void main()
^
Main.java:42: error: class, interface, or enum expected
    ZooAnimal zoo; zoo.print()
                   ^
Main.java:43: error: class, interface, or enum expected
    Cat c; c.print();
           ^
Main.java:44: error: class, interface, or enum expected
    Mouse m; m.print();
    ^
Main.java:44: error: class, interface, or enum expected
    Mouse m; m.print();
             ^
Main.java:45: error: class, interface, or enum expected
    Bear b; b.print();
    ^
Main.java:45: error: class, interface, or enum expected
    Bear b; b.print();
            ^
Main.java:46: error: class, interface, or enum expected
}
^
31 errors
stdout

Standard output is empty