• Post Reply Bookmark Topic Watch Topic
  • New Topic

Simple problem  RSS feed

 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can some one tellme why am i not able to compile this program?

abstract class a{
a(){
}
public abstract void b();
}


class h extends a{
public static void main(String[] args){

public void b(){

System.out.println(" ");
}
}
}
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could be any number of reasons, some more plausible than others. Implausible reasons could include "Your computer isn't turned on". However, if you have some symptoms of your problem -- such as error messages -- it would considerably help somebody who wanted to answer the question if you posted those symptoms.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might help if you see your code formatted to how the compiler sees it.



Do you notice the problem?

[EDIT: fixed mistake]

Henry
[ April 27, 2006: Message edited by: Henry Wong ]
 
edirg559
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

abstract class a{
a(){
}

public abstract void b();
}
}

class h extends a{
public static void main(String[] args){

public void b(){
System.out.println(" ");
}
}


From my point of view:
There is an unnecessary "}" after the public abstract void b(); line

Erik
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an unnecessary "}" after the public abstract void b(); line


Oops... wasn't paying close attention... accidentally added a brace. Will go fix it now.

Henry
 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it says illegal start of expression on this statement
public void b(){

and it says ; expected on second from last curly braces
 
Nam Lam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

...
class h extends a{
public static void main(String[] args){

public void b(){

System.out.println(" ");
}
}
}

Problem is the overriden method b() is inside main() --> not allowed.
 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so when i override a method it should not be in main method?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't declare a method inside of a method, no matter whether you are overriding or not.
 
jo sim
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks that explains it all. I appreciate your prompt response.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are just nesting braces incorrectly:
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!