• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 04 Methods and Encapsulation Jeanne Boyarsky and Scott Selikoff

 
Manish Bilung
Greenhorn
Posts: 13
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,

the following code on page 170 doesn't compile:



getting the following error:

D:\JavaCodes>javac Chapter04.java
Chapter04.java:7: error: ';' expected
int integerExpanded()
                   ^
1 error


Thanks
 
Henry Wong
author
Marshal
Pie
Posts: 22124
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Declaring a method directly inside another method is *not* allowed with Java. Are you sure you copied the code correctly?

Henry
 
Manish Bilung
Greenhorn
Posts: 13
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Declaring a method directly inside another method is *not* allowed with Java. Are you sure you copied the code correctly?

Henry


Hi Henry,

I added the main method. its not in the book.

Regards,
Manish
 
Manish Bilung
Greenhorn
Posts: 13
Chrome Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Declaring a method directly inside another method is *not* allowed with Java. Are you sure you copied the code correctly?

Henry


thanks for the help Henry. I got my answer.

The code should go like:

main(){
}

user_defined_function(){
}


Regards,
Manish
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that a main method isn't required to compile. A class is. The book includes many code snippets without putting them in a class. It is implied that it goes in a class. (This approach lets you focus on what is important.)

The actual code in the books is:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic