aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes print statement in the declaration ... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "print statement in the declaration ..." Watch "print statement in the declaration ..." New topic
Author

print statement in the declaration ...

Narasimha Rao B.
Ranch Hand

Joined: Aug 26, 2002
Posts: 205
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,


Narasimha
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
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

Joined: Oct 05, 2005
Posts: 20
Compilation error
Narasimha Rao B.
Ranch Hand

Joined: Aug 26, 2002
Posts: 205
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

Joined: Feb 26, 2005
Posts: 2061
it will be ok.

declarations can be used to:
..declare variables
..declare methods (just what you did above)
Jesus Angeles
Ranch Hand

Joined: Feb 26, 2005
Posts: 2061
look at discussion
Narasimha Rao B.
Ranch Hand

Joined: Aug 26, 2002
Posts: 205
Thanks Angeles
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: print statement in the declaration ...