• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error while running MonsterTestDrive from head First Java

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi All

I tried to compile the following code but i get 2 errors.

Errors:::
C:\java Programs>javac MonsterTestDrive.java
MonsterTestDrive.java:4: error: class, interface, or enum expected
Public class MonsterTestDrive {
^
MonsterTestDrive.java:7: error: <identifier> expected
Public static void main(String [] args) {
^
2 errors




Code:::
Public class MonsterTestDrive {


Public static void main(String [] args) {


Monster[] ma = new Monster[3] ;

ma[0] = new Vampire() ;
ma[1] = new Dragon() ;
ma[2] = new Monster() ;

for (int x = 0; x <3; x++) {

ma[x].frighten(x) ;

}
}

}


class Monster {

boolean frighten (int d) {

system.out.println ("arrrgh");

return true;
}

}


class Vampire extends Monster {

boolean frighten (int x) {

system.out.println ("a bite?!!");

return false;
}

}

class Dragon extends Monster {

boolean frighten (int degree) {

system.out.println ("breathe fire");

return true;
}

}

===================

Can somebody help me understand the issue here please?

Regards

 
Rancher
Posts: 1044
6
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java is case sensitive: public != Public.
 
Arjun Narsipur
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ivan Jozsef Balazs wrote:Java is case sensitive: public != Public.



Thanks a lot, I had overlooked it. Also I realised I had made the mistake of keeping S in "System.out." in small.

How do I know which of the key words ought ot be in caps and which in small?

 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arjun Narsipur wrote:
How do I know which of the key words ought ot be in caps and which in small?


All java keywords are lower case.
By convention, class names should be capitalized. Check out http://www.oracle.com/technetwork/java/codeconv-138413.html

I believe, modern text editors like JEdit (also) have the ability to colorize these to provide you visual clues. (e.g. the keyword "private" shows up in red color) IDEs such as Eclipse certainly do.
 
Arjun Narsipur
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:

Arjun Narsipur wrote:
How do I know which of the key words ought ot be in caps and which in small?


All java keywords are lower case.
By convention, class names should be capitalized. Check out http://www.oracle.com/technetwork/java/codeconv-138413.html

I believe, modern text editors like JEdit (also) have the ability to colorize these to provide you visual clues. (e.g. the keyword "private" shows up in red color) IDEs such as Eclipse certainly do.




Thanks a lot. I downloaded and using Netbeans and so far the experience is good. Query resolved.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic