• Post Reply Bookmark Topic Watch Topic
  • New Topic

Error while running MonsterTestDrive from head First Java  RSS feed

 
Arjun Narsipur
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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

 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java is case sensitive: public != Public.
 
Arjun Narsipur
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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?

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!