File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Clarification on the answer given Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Clarification on the answer given" Watch "Clarification on the answer given" New topic
Author

Clarification on the answer given

kc pradeep
Greenhorn

Joined: Mar 05, 2011
Posts: 28

What is the output for the below code ?



Options are
A.0 false 0
B.0 true 0
C.0 0 0
D.Compile error - static variable must be initialized before use.
Answer :
A is the correct answer.
Global and static variable need not be initialized before use. Default value of global and
static int variable is zero. Default value of boolean variable is false. Remember local
variable must be initialized before use.

My question is can printValue() access static variable p?


OCPJP 6
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

kc pradeep wrote:What is the output for the below code ?



Options are
A.0 false 0
B.0 true 0
C.0 0 0
D.Compile error - static variable must be initialized before use.
Answer :
A is the correct answer.
Global and static variable need not be initialized before use. Default value of global and
static int variable is zero. Default value of boolean variable is false. Remember local
variable must be initialized before use.

My question is can printValue() access static variable p?


why can't it ? what are your reasons that printValue() cannot access static variable p ?
kc pradeep
Greenhorn

Joined: Mar 05, 2011
Posts: 28

oops sorry, I got confused with the other rule : static functions can only access static members.
yeah, non static functions can access both, right.
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

kc pradeep wrote:oops sorry, I got confused with the other rule : static functions can only access static members.
yeah, non static functions can access both, right.


you got that.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Clarification on the answer given