wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes compilation error !! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compilation error !!" Watch "compilation error !!" New topic
Author

compilation error !!

sasank manohar
Ranch Hand

Joined: Feb 14, 2008
Posts: 186
I am using EditPlus for compiling .java 1.5.

1)//The following code compiled successfully and a Fruit1a.class file is created in "food" package

package food;
public abstract class Fruit1a
{
public abstract void orange();
}

2)//The following code is giving errors while compiling
import food.Fruit1a;
class Apple1b extends Fruit1a
{
public static void main(String args[])
{
public void orange()
{
System.out.println("hi this is orange");
}
System.out.println(" this is a apple class ,packaged in food");
}
}

the errors are...

C:\Documents and Settings\sukhdevzcomputer\mypgms\scjp>javac Apple1b.java

Apple1b.java:6: illegal start of expression
public void orange()
^
1 error

even i tried this..

C:\Documents and Settings\sukhdevzcomputer\mypgms\scjp>javac Apple1b.java -d .

Apple1b.java:6: illegal start of expression
public void orange()
^
1 error


I am not able to understand why?ofcourse iam giving those commands from windows dos prompt.


"SCJP5 | SCWCD5| DEVELOPER"
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11255
    
  16

what are you trying to do on this line:

public void orange()

The compiler thinks you are declaring a new method. the problem is, you are inside the main() method, and you can't nest methods.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11255
    
  16

Also, please check your private messages...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: compilation error !!