• Post Reply Bookmark Topic Watch Topic
  • New Topic

i got some bug here i dont know what it meens  RSS feed

 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


these are two different classes
when i put them into eklipse it marks the super() command red and says
"constructor call must be the first statement in a constructor"
i dont understend what that meens
i even put the super command in the top of the method
that didnt work either
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this:

super();

is a call to the superclass' no-arg constructor. you have it in the middle of your main method - that's not allowed.

I assume you are trying to get the code to print "A". In order to do that, you'd have to call the superclass constructor from inside your constructor for (in this case) your "B" class' constructor... and, as the error says, it must be the FIRST statement in that constructor.
 
vijay shanker
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
super() calls constructor of the super class. if you are making an object of subclass you have to make first object of superclass. And that need is achieved by this method. and it is requirement that you call that method at the first line in constructor.

If you don't do that the same thing will happen by default.
 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
correct me if i am wrong
i understood that if we make "this" or "super" commands
it will always has to be from a constructor
and to ne located in the first line
 
Campbell Ritchie
Marshal
Posts: 56534
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by donaldth smithts:
correct me if i am wrong
i understood that if we make "this" or "super" commands
it will always has to be from a constructor
and to ne located in the first line

Well, it is not "super" or "this"; it is "super();" or "this{};", but apart from that you are correct.

Fred Rosenberger has already told you. Your super(); call is not the first line of anything and it is not in a constructor. Also, the use of super. super() this. and this() are all prohibited in a static context.
 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ February 16, 2008: Message edited by: Marilyn de Queiroz ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!