Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

print statement in the declaration ...

 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have read, declarations will not produce any output, they are used to declare the methods and to declare the global variable. What happens, if had a statement -- System.out.println("testing declaration"); in the declaration..

Will it produce any output? OR will it give any error?

Thanks,
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just want to remind you where those inside declarations are put in the class generated.

public class mySample {
int i;
!!here!!
void myMethod(){}
}

If you look at my sample code above, !!here!! is where those stuff inside declarations are put.

So your question is same as, what will happen if you put those in that part of a java class.
 
Jaime Yong
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compilation error
 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Angeles,

Thanks for your reply, but if i keep my print statement in the method declaration, then what will happen? i.e.
<%!
public void myMethod(){
System.out.println("testing");
}
%>
(Just ignore if any syntax errors).

Thanks,
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it will be ok.

declarations can be used to:
..declare variables
..declare methods (just what you did above)
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at discussion
 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Angeles
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic