• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compilation error !!

 
sasank manohar
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12188
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12188
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, please check your private messages...
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic